Spaces:
Build error
Build error
Update app.py
Browse files
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 |
-
|
| 118 |
-
else:
|
| 119 |
-
return "Unable to generate a response. Please try a different query."
|
| 120 |
-
|
| 121 |
# Extract image URL from the summary
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
| 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 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
gr.
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
|
|
|
|
|
|
| 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()
|