Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -21,6 +21,7 @@ cache_dir = os.environ.get("MODEL_CACHE_DIR", "/app/cache") # Fallback to /app/
|
|
| 21 |
os.makedirs(cache_dir, exist_ok=True)
|
| 22 |
gliner_model = GLiNER.from_pretrained("urchade/gliner_medium-v2.1",cache_dir=cache_dir)
|
| 23 |
groq_client = Groq(api_key=GROQ_API_KEY)
|
|
|
|
| 24 |
|
| 25 |
def extract_entities(text):
|
| 26 |
# Tokenize the input text first
|
|
@@ -94,13 +95,11 @@ async def chat(request: Request, message: str = Form(...)):
|
|
| 94 |
bot_reply = generate_response(message, answer)
|
| 95 |
else:
|
| 96 |
bot_reply = "Sorry, I couldn't find a suitable answer. Please contact support."
|
|
|
|
|
|
|
| 97 |
|
| 98 |
-
chat_history = [
|
| 99 |
-
{"sender": "User", "message": message},
|
| 100 |
-
{"sender": "Bot", "message": bot_reply}
|
| 101 |
-
]
|
| 102 |
return templates.TemplateResponse("chat.html", {
|
| 103 |
"request": request,
|
| 104 |
-
"chat_history":
|
| 105 |
"entities": entity_info
|
| 106 |
})
|
|
|
|
| 21 |
os.makedirs(cache_dir, exist_ok=True)
|
| 22 |
gliner_model = GLiNER.from_pretrained("urchade/gliner_medium-v2.1",cache_dir=cache_dir)
|
| 23 |
groq_client = Groq(api_key=GROQ_API_KEY)
|
| 24 |
+
chat_memory=[]
|
| 25 |
|
| 26 |
def extract_entities(text):
|
| 27 |
# Tokenize the input text first
|
|
|
|
| 95 |
bot_reply = generate_response(message, answer)
|
| 96 |
else:
|
| 97 |
bot_reply = "Sorry, I couldn't find a suitable answer. Please contact support."
|
| 98 |
+
chat_memory.append({"sender": "User", "message": message})
|
| 99 |
+
chat_memory.append({"sender": "Bot", "message": bot_reply})
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
return templates.TemplateResponse("chat.html", {
|
| 102 |
"request": request,
|
| 103 |
+
"chat_history": chat_memory,
|
| 104 |
"entities": entity_info
|
| 105 |
})
|