Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -152,27 +152,21 @@ async def ask(query: Query):
|
|
| 152 |
|
| 153 |
loop = asyncio.get_event_loop()
|
| 154 |
|
| 155 |
-
|
| 156 |
# qa_chain.run(prompt, callbacks=[timeout_callback]),
|
| 157 |
loop.run_in_executor(None, qa_chain.run, prompt),
|
| 158 |
timeout=360
|
| 159 |
)
|
| 160 |
|
| 161 |
-
if not
|
| 162 |
raise ValueError("Empty answer returned from model")
|
| 163 |
|
| 164 |
-
if
|
| 165 |
-
response_text = answer.split('Answer:')[-1].strip()
|
| 166 |
-
elif 'الإجابة:' in answer:
|
| 167 |
-
response_text = answer.split('الإجابة:')[-1].strip()
|
| 168 |
-
else:
|
| 169 |
-
response_text = answer.strip()
|
| 170 |
-
|
| 171 |
|
| 172 |
return {
|
| 173 |
"status": "success",
|
|
|
|
| 174 |
"answer": answer,
|
| 175 |
-
"response": response_text,
|
| 176 |
"language": detect(query.question)
|
| 177 |
}
|
| 178 |
|
|
@@ -195,10 +189,13 @@ def chat(query: Query):
|
|
| 195 |
|
| 196 |
prompt = generate_prompt(query.question)
|
| 197 |
|
| 198 |
-
|
| 199 |
|
| 200 |
-
|
|
|
|
| 201 |
|
|
|
|
|
|
|
| 202 |
"answer": answer
|
| 203 |
}
|
| 204 |
|
|
|
|
| 152 |
|
| 153 |
loop = asyncio.get_event_loop()
|
| 154 |
|
| 155 |
+
response = await asyncio.wait_for(
|
| 156 |
# qa_chain.run(prompt, callbacks=[timeout_callback]),
|
| 157 |
loop.run_in_executor(None, qa_chain.run, prompt),
|
| 158 |
timeout=360
|
| 159 |
)
|
| 160 |
|
| 161 |
+
if not response:
|
| 162 |
raise ValueError("Empty answer returned from model")
|
| 163 |
|
| 164 |
+
answer = response.split("Answer:")[-1].strip() if "Answer:" in response else response.split("الإجابة:")[-1].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
return {
|
| 167 |
"status": "success",
|
| 168 |
+
"response": response,
|
| 169 |
"answer": answer,
|
|
|
|
| 170 |
"language": detect(query.question)
|
| 171 |
}
|
| 172 |
|
|
|
|
| 189 |
|
| 190 |
prompt = generate_prompt(query.question)
|
| 191 |
|
| 192 |
+
response = qa_chain.run(prompt)
|
| 193 |
|
| 194 |
+
answer = response.split("Answer:")[-1].strip() if "Answer:" in response else response.split("الإجابة:")[-1].strip()
|
| 195 |
+
|
| 196 |
|
| 197 |
+
return {
|
| 198 |
+
"response": response,
|
| 199 |
"answer": answer
|
| 200 |
}
|
| 201 |
|