Spaces:
Build error
Build error
Update Gradio_UI.py
Browse files193 unmodified lines19419519619719819920020120220320456 unmodified lines2612622632642652662676 unmodified lines274275276277278279280281282283284285286287288289290291292293294295193 unmodified linesmessages.append(gr.ChatMessage(role="user", content=prompt))yield messagesfor msg in stream_to_gradio(self.agent, task=prompt, reset_agent_memory=False):messages.append(msg)yield messagesyield messagesdef upload_file(self,file,56 unmodified linesdef launch(self, **kwargs):import gradio as grwith gr.Blocks(fill_height=True) as demo:stored_messages = gr.State([])file_uploads_log = gr.State([])chatbot = gr.Chatbot(6 unmodified linesresizeable=True,scale=1,)# If an upload folder is provided, enable the upload featureif self.file_upload_folder is not None:upload_file = gr.File(label="Upload a file")upload_status = gr.Textbox(label="Upload Status", interactive=False, visible=False)upload_file.change(self.upload_file,[upload_file, file_uploads_log],[upload_status, file_uploads_log],)text_input = gr.Textbox(lines=1, label="Chat Message")text_input.submit(self.log_user_message,[text_input, file_uploads_log],[stored_messages, text_input],).then(self.interact_with_agent, [stored_messages, chatbot], [chatbot])demo.launch(debug=True, share=True, **kwargs)193 unmodified lines19419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722856 unmodified lines2852862872882892902912922932942952962972982993003013023033043053063073083093106 unmodified lines317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385193 unmodified linesmessages.append(gr.ChatMessage(role="user", content=prompt))yield messages# Add loading messageloading_msg = gr.ChatMessage(role="assistant",content="Thinking...🤔👩🏽⚕️👨🏽⚕️",metadata={"class": "loading-message"})messages.append(loading_msg)yield messages# Process agent responsefor msg in stream_to_gradio(self.agent, task=prompt, reset_agent_memory=False):# Remove loading message before adding real responsesif len(messages) > 0 and messages[-1].metadata.get("class") == "loading-message":messages.pop()messages.append(msg)yield messages# Ensure loading message is removed at the endif len(messages) > 0 and messages[-1].metadata.get("class") == "loading-message":messages.pop()yield messages# for msg in stream_to_gradio(self.agent, task=prompt, reset_agent_memory=False):# messages.append(msg)# yield messages# yield messagesdef upload_file(self,file,56 unmodified linesdef launch(self, **kwargs):import gradio as grwith gr.Blocks(title="Health Agent",fill_height=True,css=""".loading-message {animation: pulse 2s cubic-bezier(.4,0,.6,1) infinite;}@keyframes pulse {0%, 100% { opacity: 1; }50% { opacity: 0.5; }}""") as demo:gr.Markdown("""# NELA - AI-Powered Health AdvisorI am NELA, your AI-powered health advisor. I can help you track your health, provide symptom analysis, suggest possible diagnoses, and offer wellness recommendations.Ask me about symptoms, treatments, medications, or how to maintain a healthy lifestyle!""")stored_messages = gr.State([])file_uploads_log = gr.State([])chatbot = gr.Chatbot(6 unmodified linesresizeable=True,scale=1,)text_input = gr.Textbox(label="Ask me anything about your health",placeholder="Type your question here...",)submit_button = gr.Button("Send")gr.Examples(examples=["What could be the possible causes of persistent headaches?","Suggest some home remedies for managing cold and flu symptoms.","What are the early signs of diabetes?","How can I lower my blood pressure naturally?","What should I do if I experience sudden chest pain?","Which foods are best for boosting my immune system?","How can I track my daily health using smart devices?","What are common symptoms of dehydration and how can I prevent it?","Explain the importance of regular health check-ups.","What should I include in a balanced diet for better heart health?"],inputs=text_input,label="Example Questions")text_input.submit(self.log_user_message,[text_input, file_uploads_log],[stored_messages, text_input],).then(self.interact_with_agent, [stored_messages, chatbot], [chatbot])submit_button.click(self.log_user_message,[text_input, file_uploads_log],[stored_messages, text_input],).then(self.interact_with_agent, [stored_messages, chatbot], [chatbot])# with gr.Blocks(fill_height=True) as demo:# stored_messages = gr.State([])# file_uploads_log = gr.State([])# chatbot = gr.Chatbot(# label="Agent",# type="messages",# avatar_images=(# None,# "https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/communication/Alfred.png",# ),# resizeable=True,# scale=1,# )# # If an upload folder is provided, enable the upload feature# if self.file_upload_folder is not None:# upload_file = gr.File(label="Upload a file")# upload_status = gr.Textbox(label="Upload Status", interactive=False, visible=False)# upload_file.change(# self.upload_file,# [upload_file, file_uploads_log],# [upload_status, file_uploads_log],# )# text_input = gr.Textbox(lines=1, label="Chat Message")# text_input.submit(# self.log_user_message,# [text_input, file_uploads_log],# [stored_messages, text_input],# ).then(self.interact_with_agent, [stored_messages, chatbot], [chatbot])demo.launch(debug=True, share=True, **kwargs)
Gradio_UI.py+101-11