Spaces:
Build error
Build error
Update app.py
Browse files37 unmodified lines3839404142434426 unmodified lines7172737475767778795 unmodified lines858687888990913 unmodified lines959697989910010110210310410510613 unmodified lines12012112212312412512612712812913013113213336 unmodified lines17017117217317417537 unmodified linesglobal chat_historytry:if not user_message.strip():return [("system", "Please enter a question.")]# Add user message to chat history26 unmodified linesimg.save(buffered, format="PNG")img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")img = f'<img src="data:image/png;base64,{img_str}" style="width:450px; height:400px;">'ai_response = img + ai_responseuser_message = visual_query.strip()5 unmodified linesreturn chat_historyexcept Exception as e:chat_history.append((visual_query, f"Sorry, I couldn't process your request. Please try after some time."))return chat_history# Chat handling functiondef chat_interaction(user_message):3 unmodified lineswith gr.Blocks(theme="soft") as app: # Use the 'soft' themegr.Markdown("<h1 style='color:blue;'>Agentic AI - Chat with Documents & Database</h1>",elem_id="title")with gr.Tab("Chat"):chat_box = gr.Chatbot(label="Chat History")with gr.Row(): # Place elements in the same rowwith gr.Column(scale=2):user_input = gr.Textbox(13 unmodified linesoutputs=[chat_box, user_input])with gr.Tab("File Upload"):upload_button = gr.UploadButton(label="Upload your file (PDF, Excel, Docx, Txt, CSV)",file_types=[".pdf", ".xlsx", ".docx", ".txt", ".csv"],file_count="single")file_output = gr.Textbox(label="File Processing Output")upload_button.upload(fn=handle_file_uploads, inputs=upload_button, outputs=[file_output])# Clear input field functiondef clear_input():36 unmodified lines#title {margin-bottom: 10px; /* Space below the title */text-align: center;}"""37 unmodified lines383940414243444526 unmodified lines7273747576777879805 unmodified lines868788899091923 unmodified lines9697989910010110210310410510610713 unmodified lines12112212312412512612712812913013113213313436 unmodified lines17117217317417517617717817918018137 unmodified linesglobal chat_historytry:if not user_message.strip():chat_history.append(("AI: ", "Please enter a question."))# Add user message to chat history26 unmodified linesimg.save(buffered, format="PNG")img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")img = f'<img src="data:image/png;base64,{img_str}" style="width:600px; height:500px;">'ai_response = img + ai_responseuser_message = visual_query.strip()5 unmodified linesreturn chat_historyexcept Exception as e:chat_history.append((visual_query, f"As you know I am still learning at this moment I am not able to respond to your question.\nThank you for your patience!"))return chat_history# Chat handling functiondef chat_interaction(user_message):3 unmodified lineswith gr.Blocks(theme="soft") as app: # Use the 'soft' themegr.Markdown("<h1 style='color:blue;'>Material Forecast - Generative AI Agent</h1>",elem_id="title")with gr.Tab("Chat"):chat_box = gr.Chatbot(label="Chat History",elem_id="chatbot_gpt")with gr.Row(): # Place elements in the same rowwith gr.Column(scale=2):user_input = gr.Textbox(13 unmodified linesoutputs=[chat_box, user_input])"""with gr.Tab("File Upload"):upload_button = gr.UploadButton(label="Upload your file (PDF, Excel, Docx, Txt, CSV)",file_types=[".pdf", ".xlsx", ".docx", ".txt", ".csv"],file_count="single")file_output = gr.Textbox(label="File Processing Output")upload_button.upload(fn=handle_file_uploads, inputs=upload_button, outputs=[file_output])"""# Clear input field functiondef clear_input():36 unmodified lines#title {margin-bottom: 10px; /* Space below the title */text-align: center;#chatbot_gpt {height: 600px !important; /* Adjust height as needed */}}"""
app.py+14-8