Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -211,9 +211,13 @@ def chat_interface(message, history):
|
|
| 211 |
return "Please enter a question about NASA space biology research."
|
| 212 |
|
| 213 |
try:
|
|
|
|
|
|
|
| 214 |
response = generate_enhanced_response(message)
|
| 215 |
context_results = search_context(message, top_k=8)
|
| 216 |
|
|
|
|
|
|
|
| 217 |
# Format sources
|
| 218 |
sources_info = f"Based on {len(context_results)} NASA research papers"
|
| 219 |
if context_results:
|
|
@@ -232,6 +236,9 @@ def chat_interface(message, history):
|
|
| 232 |
return formatted_response
|
| 233 |
|
| 234 |
except Exception as e:
|
|
|
|
|
|
|
|
|
|
| 235 |
return f"❌ Error: {str(e)}"
|
| 236 |
|
| 237 |
# Create Gradio interface
|
|
@@ -278,12 +285,20 @@ with gr.Blocks(title="NASA Bioscience AI (Lightweight)", theme=gr.themes.Soft())
|
|
| 278 |
demo.load(load_models, outputs=gr.Textbox(visible=False))
|
| 279 |
|
| 280 |
# Event handlers
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
|
| 288 |
if __name__ == "__main__":
|
| 289 |
demo.launch()
|
|
|
|
| 211 |
return "Please enter a question about NASA space biology research."
|
| 212 |
|
| 213 |
try:
|
| 214 |
+
print(f"Processing query: {message}") # Debug print
|
| 215 |
+
|
| 216 |
response = generate_enhanced_response(message)
|
| 217 |
context_results = search_context(message, top_k=8)
|
| 218 |
|
| 219 |
+
print(f"Generated response length: {len(response)}") # Debug print
|
| 220 |
+
|
| 221 |
# Format sources
|
| 222 |
sources_info = f"Based on {len(context_results)} NASA research papers"
|
| 223 |
if context_results:
|
|
|
|
| 236 |
return formatted_response
|
| 237 |
|
| 238 |
except Exception as e:
|
| 239 |
+
print(f"Error in chat_interface: {e}") # Debug print
|
| 240 |
+
import traceback
|
| 241 |
+
traceback.print_exc()
|
| 242 |
return f"❌ Error: {str(e)}"
|
| 243 |
|
| 244 |
# Create Gradio interface
|
|
|
|
| 285 |
demo.load(load_models, outputs=gr.Textbox(visible=False))
|
| 286 |
|
| 287 |
# Event handlers
|
| 288 |
+
def respond(message, history):
|
| 289 |
+
"""Handle user input and generate response"""
|
| 290 |
+
if not message.strip():
|
| 291 |
+
return history, ""
|
| 292 |
+
|
| 293 |
+
# Generate response
|
| 294 |
+
response = chat_interface(message, history)
|
| 295 |
+
|
| 296 |
+
# Add to history
|
| 297 |
+
history.append([message, response])
|
| 298 |
+
return history, ""
|
| 299 |
+
|
| 300 |
+
msg.submit(respond, [msg, chatbot], [chatbot, msg])
|
| 301 |
+
send_btn.click(respond, [msg, chatbot], [chatbot, msg])
|
| 302 |
|
| 303 |
if __name__ == "__main__":
|
| 304 |
demo.launch()
|