Spaces:
Sleeping
Sleeping
Update app.py
Browse files53 unmodified lines545556575859606 unmodified lines676869707172733 unmodified lines77787980818283848586878829 unmodified lines1181191201211221231247 unmodified lines13213313413513613713813912 unmodified lines1521531541551561571581591601611621631641651661671681691701711721731741751761771781791801816 unmodified lines1881891901911921931941951961971981992002015 unmodified lines2072082092102112122132142152162172182192202212222232242252262272282291 unmodified line23123223323423523623723823924024124224324424524624724824911 unmodified lines26126226326426526626726826927018 unmodified lines2892902912922932942952962972982993003013 unmodified lines3053063073083093103116 unmodified lines3183193203213223233243253263273283293303313323333343353363373383393403413423433443451 unmodified line34734834935035135235316 unmodified lines3703713723733743753764 unmodified lines38138238338453 unmodified lines"""# =========================================================# AI FUNCTION# =========================================================@spaces.GPU(duration=45)6 unmodified lines}]# Add conversation historyif history:for item in history:3 unmodified linescontent = item.get("content")if role in ["user", "assistant"] and isinstance(content, str):messages.append({"role": role,"content": content})# Current questionmessages.append({"role": "user","content": message29 unmodified lines# =========================================================# CUSTOM DESIGN# =========================================================css = """7 unmodified linesmargin: auto !important;}/* HEADER */.fvb-header {text-align: center;padding-top: 25px;12 unmodified linesmargin-top: 5px;}/* CHAT */.fvb-chat {border-radius: 18px !important;border: 1px solid #e5e7eb !important;}/* MESSAGE BOX */#message-box textarea {border-radius: 15px !important;font-size: 16px !important;}/* SEND BUTTON */#send-button {border-radius: 14px !important;min-height: 55px !important;font-weight: 600 !important;}/* SUGGESTIONS */.suggestion-btn {border-radius: 22px !important;background: white !important;6 unmodified linesbackground: #f3f6fa !important;}/* CLEAR */#clear-button {border-radius: 12px !important;}/* FOOTER */.fvb-footer {text-align: center;color: #8a8f98;5 unmodified lines# =========================================================# USER INTERFACE# =========================================================with gr.Blocks(title="FUTUREVIDYABOX.AI",css=css,theme=gr.themes.Soft(primary_hue="blue",secondary_hue="blue",neutral_hue="slate")) as demo:# HEADERgr.HTML("""<div class="fvb-header"><div class="fvb-title">FUTUREVIDYABOX.AI</div>1 unmodified line<div class="fvb-subtitle">Your educational and AI assistant</div></div>""")# CHATchatbot = gr.Chatbot(label="FVB AI",type="messages",height=500,elem_classes="fvb-chat")# INPUT + SENDwith gr.Row():message = gr.Textbox(11 unmodified lineselem_id="send-button")# =====================================================# SUGGESTION BUTTONS# =====================================================gr.Markdown("### Try asking")with gr.Row():18 unmodified lineselem_classes="suggestion-btn")# CLEARclear = gr.Button("Clear chat",elem_id="clear-button")# FOOTERgr.HTML("""<div class="fvb-footer">3 unmodified lines)# =====================================================# CHAT FUNCTION# =====================================================def respond(message_text, chat_history):6 unmodified lineschat_history)new_history = list(chat_history)new_history.append({"role": "user","content": message_text})new_history.append({"role": "assistant","content": answer})return "", new_history# NORMAL SENDsend.click(respond,inputs=[message, chatbot],outputs=[message, chatbot])# ENTER TO SENDmessage.submit(respond,inputs=[message, chatbot],1 unmodified line)# =====================================================# SUGGESTION BUTTONS# =====================================================suggestion1.click(16 unmodified linesoutputs=message)# CLEAR CHATclear.click(lambda: [],outputs=chatbot4 unmodified lines# START# =========================================================demo.launch()53 unmodified lines545556575859606 unmodified lines676869707172733 unmodified lines77787980818283848586878829 unmodified lines1181191201211221231247 unmodified lines13213313413513613712 unmodified lines1501511521531541551561571581591601611621631641651661671681691701716 unmodified lines1781791801811821831841851861875 unmodified lines1931941951961971981992002012022032042052062072082091 unmodified line21121221321421521621721821922022122222322422522622711 unmodified lines23924024124224324418 unmodified lines2632642652662672682692702712722733 unmodified lines2772782792802812822836 unmodified lines2902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203211 unmodified line32332432532632732832916 unmodified lines3463473483493503513523534 unmodified lines35835936036136236336436536636736853 unmodified lines"""# =========================================================# AI# =========================================================@spaces.GPU(duration=45)6 unmodified lines}]# History is already in messages formatif history:for item in history:3 unmodified linescontent = item.get("content")if role in ["user", "assistant"] and isinstance(content, str):messages.append({"role": role,"content": content})messages.append({"role": "user","content": message29 unmodified lines# =========================================================# CSS# =========================================================css = """7 unmodified linesmargin: auto !important;}.fvb-header {text-align: center;padding-top: 25px;12 unmodified linesmargin-top: 5px;}.fvb-chat {border-radius: 18px !important;border: 1px solid #e5e7eb !important;}#message-box textarea {border-radius: 15px !important;font-size: 16px !important;}#send-button {border-radius: 14px !important;min-height: 55px !important;font-weight: 600 !important;}.suggestion-btn {border-radius: 22px !important;background: white !important;6 unmodified linesbackground: #f3f6fa !important;}#clear-button {border-radius: 12px !important;}.fvb-footer {text-align: center;color: #8a8f98;5 unmodified lines# =========================================================# UI# =========================================================with gr.Blocks(title="FUTUREVIDYABOX.AI") as demo:gr.HTML("""<div class="fvb-header"><div class="fvb-title">FUTUREVIDYABOX.AI</div>1 unmodified line<div class="fvb-subtitle">Your educational and AI assistant</div></div>""")chatbot = gr.Chatbot(label="FVB AI",height=500,elem_classes="fvb-chat")with gr.Row():message = gr.Textbox(11 unmodified lineselem_id="send-button")gr.Markdown("### Try asking")with gr.Row():18 unmodified lineselem_classes="suggestion-btn")clear = gr.Button("Clear chat",elem_id="clear-button")gr.HTML("""<div class="fvb-footer">3 unmodified lines)# =====================================================# RESPONSE# =====================================================def respond(message_text, chat_history):6 unmodified lineschat_history)chat_history = chat_history or []chat_history = list(chat_history)chat_history.append({"role": "user","content": message_text})chat_history.append({"role": "assistant","content": answer})return "", chat_history# SEND BUTTONsend.click(respond,inputs=[message, chatbot],outputs=[message, chatbot])# ENTERmessage.submit(respond,inputs=[message, chatbot],1 unmodified line)# =====================================================# SUGGESTIONS# =====================================================suggestion1.click(16 unmodified linesoutputs=message)# CLEARclear.click(lambda: [],outputs=chatbot4 unmodified lines# START# =========================================================demo.launch(theme=gr.themes.Soft(primary_hue="blue",secondary_hue="blue",neutral_hue="slate"),css=css)
app.py+30-46