Shreyas094 commited on
Commit
e8cb689
·
verified ·
1 Parent(s): ab836a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -40
app.py CHANGED
@@ -114,16 +114,15 @@ def respond(message, chat_history, model, temperature, num_api_calls):
114
 
115
  if final_summary:
116
  conversation_manager.add_interaction(original_query, final_summary)
117
- return final_summary
118
- else:
119
- return "Unable to generate a response. Please try a different query."
120
-
121
  # Extract image URL from the summary
122
- image_url = None
123
- if "Image found:" in final_summary:
124
- image_url = final_summary.split("URL: ")[1].split("\n")[0]
125
-
126
- return final_summary, image_url
 
 
127
 
128
  # The rest of your code (CSS, theme, and Gradio interface setup) remains the same
129
  css = """
@@ -151,37 +150,39 @@ theme = gr.themes.Soft(
151
  code_background_fill_dark="#140b0b"
152
  )
153
 
154
- demo = gr.Interface(
155
- fn=respond,
156
- inputs=[
157
- gr.Textbox(placeholder=custom_placeholder, label="Message"),
158
- gr.State([]), # For chat history
159
- gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[2]),
160
- gr.Slider(minimum=0.1, maximum=1.0, value=0.2, step=0.1, label="Temperature"),
161
- gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of API Calls")
162
- ],
163
- outputs=[
164
- gr.Textbox(label="Response"),
165
- gr.Image(label="Related Image")
166
- ],
167
- title="AI-powered Web Search and PDF Chat Assistant",
168
- description="This AI-powered Web Search and PDF Chat Assistant combines real-time web search capabilities with advanced language processing.",
169
- theme=theme,
170
- css=css,
171
- examples=[
172
- ["What is AI"],
173
- ["Any recent news on US Banks"],
174
- ["Who is Donald Trump"]
175
- ],
176
- cache_examples=False,
177
- analytics_enabled=False,
178
- textbox=gr.Textbox(placeholder=custom_placeholder, container=False, scale=7),
179
- chatbot=gr.Chatbot(
180
- show_copy_button=True,
181
- likeable=True,
182
- layout="bubble",
183
- height=400,
 
 
184
  )
185
- )
186
 
187
  demo.launch()
 
114
 
115
  if final_summary:
116
  conversation_manager.add_interaction(original_query, final_summary)
117
+
 
 
 
118
  # Extract image URL from the summary
119
+ image_url = None
120
+ if "Image found:" in final_summary:
121
+ image_url = final_summary.split("URL: ")[1].split("\n")[0]
122
+
123
+ return final_summary, image_url
124
+ else:
125
+ return "Unable to generate a response. Please try a different query.", None
126
 
127
  # The rest of your code (CSS, theme, and Gradio interface setup) remains the same
128
  css = """
 
150
  code_background_fill_dark="#140b0b"
151
  )
152
 
153
+ with gr.Blocks(theme=theme, css=css) as demo:
154
+ gr.Markdown("# AI-powered Web Search and PDF Chat Assistant")
155
+ gr.Markdown("This AI-powered Web Search and PDF Chat Assistant combines real-time web search capabilities with advanced language processing.")
156
+
157
+ with gr.Row():
158
+ with gr.Column(scale=7):
159
+ chatbot = gr.Chatbot(
160
+ show_copy_button=True,
161
+ likeable=True,
162
+ layout="bubble",
163
+ height=400,
164
+ )
165
+ msg = gr.Textbox(placeholder=custom_placeholder, container=False, scale=7)
166
+ clear = gr.Button("Clear")
167
+
168
+ with gr.Column(scale=3):
169
+ model = gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[2])
170
+ temperature = gr.Slider(minimum=0.1, maximum=1.0, value=0.2, step=0.1, label="Temperature")
171
+ num_api_calls = gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of API Calls")
172
+ image_output = gr.Image(label="Related Image")
173
+
174
+ def user(user_message, history):
175
+ return "", history + [[user_message, None]]
176
+
177
+ def bot(history, model, temperature, num_api_calls):
178
+ user_message = history[-1][0]
179
+ bot_response, image_url = respond(user_message, history, model, temperature, num_api_calls)
180
+ history[-1][1] = bot_response
181
+ return history, image_url
182
+
183
+ msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
184
+ bot, [chatbot, model, temperature, num_api_calls], [chatbot, image_output]
185
  )
186
+ clear.click(lambda: None, None, chatbot, queue=False)
187
 
188
  demo.launch()