Redmind commited on
Commit
9ef8268
·
verified ·
1 Parent(s): 16bf86a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -38,7 +38,8 @@ def handle_chat(user_message):
38
  global chat_history
39
  try:
40
  if not user_message.strip():
41
- return [("system", "Please enter a question.")]
 
42
 
43
  # Add user message to chat history
44
 
@@ -71,9 +72,9 @@ def handle_chat(user_message):
71
  img.save(buffered, format="PNG")
72
  img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
73
 
74
- img = f'<img src="data:image/png;base64,{img_str}" style="width:450px; height:400px;">'
75
 
76
- ai_response = img + ai_response
77
 
78
  user_message = visual_query.strip()
79
 
@@ -85,7 +86,7 @@ def handle_chat(user_message):
85
  return chat_history
86
 
87
  except Exception as e:
88
- chat_history.append((visual_query, f"Sorry, I couldn't process your request. Please try after some time."))
89
  return chat_history
90
  # Chat handling function
91
  def chat_interaction(user_message):
@@ -95,12 +96,12 @@ def chat_interaction(user_message):
95
 
96
  with gr.Blocks(theme="soft") as app: # Use the 'soft' theme
97
  gr.Markdown(
98
- "<h1 style='color:blue;'>Agentic AI - Chat with Documents & Database</h1>",
99
  elem_id="title"
100
  )
101
 
102
  with gr.Tab("Chat"):
103
- chat_box = gr.Chatbot(label="Chat History")
104
  with gr.Row(): # Place elements in the same row
105
  with gr.Column(scale=2):
106
  user_input = gr.Textbox(
@@ -120,14 +121,14 @@ with gr.Blocks(theme="soft") as app: # Use the 'soft' theme
120
  outputs=[chat_box, user_input]
121
  )
122
 
123
- with gr.Tab("File Upload"):
124
  upload_button = gr.UploadButton(
125
  label="Upload your file (PDF, Excel, Docx, Txt, CSV)",
126
  file_types=[".pdf", ".xlsx", ".docx", ".txt", ".csv"],
127
  file_count="single"
128
  )
129
  file_output = gr.Textbox(label="File Processing Output")
130
- upload_button.upload(fn=handle_file_uploads, inputs=upload_button, outputs=[file_output])
131
 
132
  # Clear input field function
133
  def clear_input():
@@ -170,6 +171,11 @@ app.css = """
170
  #title {
171
  margin-bottom: 10px; /* Space below the title */
172
  text-align: center;
 
 
 
 
 
173
  }
174
  """
175
 
 
38
  global chat_history
39
  try:
40
  if not user_message.strip():
41
+ chat_history.append(("AI: ", "Please enter a question."))
42
+
43
 
44
  # Add user message to chat history
45
 
 
72
  img.save(buffered, format="PNG")
73
  img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
74
 
75
+ img = f'<img src="data:image/png;base64,{img_str}" style="width:600px; height:500px;">'
76
 
77
+ ai_response = img + ai_response
78
 
79
  user_message = visual_query.strip()
80
 
 
86
  return chat_history
87
 
88
  except Exception as e:
89
+ 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!"))
90
  return chat_history
91
  # Chat handling function
92
  def chat_interaction(user_message):
 
96
 
97
  with gr.Blocks(theme="soft") as app: # Use the 'soft' theme
98
  gr.Markdown(
99
+ "<h1 style='color:blue;'>Material Forecast - Generative AI Agent</h1>",
100
  elem_id="title"
101
  )
102
 
103
  with gr.Tab("Chat"):
104
+ chat_box = gr.Chatbot(label="Chat History",elem_id="chatbot_gpt")
105
  with gr.Row(): # Place elements in the same row
106
  with gr.Column(scale=2):
107
  user_input = gr.Textbox(
 
121
  outputs=[chat_box, user_input]
122
  )
123
 
124
+ """with gr.Tab("File Upload"):
125
  upload_button = gr.UploadButton(
126
  label="Upload your file (PDF, Excel, Docx, Txt, CSV)",
127
  file_types=[".pdf", ".xlsx", ".docx", ".txt", ".csv"],
128
  file_count="single"
129
  )
130
  file_output = gr.Textbox(label="File Processing Output")
131
+ upload_button.upload(fn=handle_file_uploads, inputs=upload_button, outputs=[file_output])"""
132
 
133
  # Clear input field function
134
  def clear_input():
 
171
  #title {
172
  margin-bottom: 10px; /* Space below the title */
173
  text-align: center;
174
+
175
+ #chatbot_gpt {
176
+ height: 600px !important; /* Adjust height as needed */
177
+ }
178
+
179
  }
180
  """
181