Update app.py
Browse files
app.py
CHANGED
|
@@ -24,7 +24,21 @@ def query_huggingface(prompt):
|
|
| 24 |
"options": {"wait_for_model": True}
|
| 25 |
}
|
| 26 |
response = requests.post(API_URL, headers=headers, json=payload)
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# UI
|
| 30 |
st.title("💬 Ask Me Anything - Tech RAG Chatbot")
|
|
|
|
| 24 |
"options": {"wait_for_model": True}
|
| 25 |
}
|
| 26 |
response = requests.post(API_URL, headers=headers, json=payload)
|
| 27 |
+
|
| 28 |
+
# Check for HTTP or decoding errors
|
| 29 |
+
if response.status_code != 200:
|
| 30 |
+
return f"❌ HF API Error: {response.status_code} - {response.text}"
|
| 31 |
+
|
| 32 |
+
try:
|
| 33 |
+
result = response.json()
|
| 34 |
+
if isinstance(result, list) and "generated_text" in result[0]:
|
| 35 |
+
return result[0]["generated_text"]
|
| 36 |
+
elif isinstance(result, dict) and "error" in result:
|
| 37 |
+
return f"❌ Model Error: {result['error']}"
|
| 38 |
+
else:
|
| 39 |
+
return "⚠️ Unexpected model response format."
|
| 40 |
+
except Exception as e:
|
| 41 |
+
return f"⚠️ Failed to parse response: {e}"
|
| 42 |
|
| 43 |
# UI
|
| 44 |
st.title("💬 Ask Me Anything - Tech RAG Chatbot")
|