Spaces:
Sleeping
Sleeping
Sandhya
commited on
Commit
·
c886e14
1
Parent(s):
9142873
First Commit
Browse files
app.py
CHANGED
|
@@ -10,7 +10,7 @@ from typing import Optional, Literal
|
|
| 10 |
|
| 11 |
load_dotenv()
|
| 12 |
HF_TOKEN=os.getenv("HF_TOKEN")
|
| 13 |
-
HF_MODEL=os.getenv("HF_MODEL","
|
| 14 |
app=FastAPI(title="MODEL-CARD-CHATBOT")
|
| 15 |
app.add_middleware(CORSMiddleware,allow_origins=["*"],allow_methods=["*"],allow_headers=["*"])
|
| 16 |
|
|
@@ -67,9 +67,15 @@ async def chat_function(user_message, history, model_id):
|
|
| 67 |
history = history + [(user_message, None)]
|
| 68 |
try:
|
| 69 |
response = ""
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
final_response = response or "⚠️ Sorry, I couldn't generate a response."
|
| 74 |
history[-1] = (user_message, final_response)
|
| 75 |
except Exception as e:
|
|
|
|
| 10 |
|
| 11 |
load_dotenv()
|
| 12 |
HF_TOKEN=os.getenv("HF_TOKEN")
|
| 13 |
+
HF_MODEL=os.getenv("HF_MODEL","google/gemma-2-2b")
|
| 14 |
app=FastAPI(title="MODEL-CARD-CHATBOT")
|
| 15 |
app.add_middleware(CORSMiddleware,allow_origins=["*"],allow_methods=["*"],allow_headers=["*"])
|
| 16 |
|
|
|
|
| 67 |
history = history + [(user_message, None)]
|
| 68 |
try:
|
| 69 |
response = ""
|
| 70 |
+
try:
|
| 71 |
+
async for output in agent_instance.run(prompt):
|
| 72 |
+
if hasattr(output, "content") and output.content:
|
| 73 |
+
response = output.content
|
| 74 |
+
except TypeError:
|
| 75 |
+
for output in agent_instance.run(prompt):
|
| 76 |
+
if hasattr(output, "content") and output.content:
|
| 77 |
+
response = output.content
|
| 78 |
+
|
| 79 |
final_response = response or "⚠️ Sorry, I couldn't generate a response."
|
| 80 |
history[-1] = (user_message, final_response)
|
| 81 |
except Exception as e:
|