Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -51,16 +51,21 @@ def chatbot(pdf_file, user_question):
|
|
51 |
# Use only the first chunk (to optimize token usage)
|
52 |
prompt = f"Based on this document, answer the question:\n\nDocument:\n{chunks[0]}\n\nQuestion: {user_question}"
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
# Send to Together.AI (Mistral-7B)
|
55 |
-
response = together.Completion.create(
|
56 |
-
model="mistralai/Mistral-7B-Instruct-v0.1",
|
57 |
-
prompt=prompt,
|
58 |
-
max_tokens=200,
|
59 |
-
temperature=0.7,
|
60 |
-
)
|
61 |
|
62 |
-
# Return chatbot's response
|
63 |
-
return response.choices[0].text
|
64 |
|
65 |
|
66 |
# Gradio Interface
|
|
|
51 |
# Use only the first chunk (to optimize token usage)
|
52 |
prompt = f"Based on this document, answer the question:\n\nDocument:\n{chunks[0]}\n\nQuestion: {user_question}"
|
53 |
|
54 |
+
try:
|
55 |
+
response = together.chat.completions.create(
|
56 |
+
model="mistralai/Mistral-7B-Instruct-v0.1",
|
57 |
+
prompt=prompt,
|
58 |
+
max_tokens=200,
|
59 |
+
temperature=0.7,
|
60 |
+
)
|
61 |
+
|
62 |
+
# Return chatbot's response
|
63 |
+
return response.choices[0].message.content.strip()
|
64 |
+
except Exception as e:
|
65 |
+
return f"Error generating response: {e}"
|
66 |
+
|
67 |
# Send to Together.AI (Mistral-7B)
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
|
|
|
|
69 |
|
70 |
|
71 |
# Gradio Interface
|