Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -121,7 +121,8 @@ def generate_response(session_id, user_text, enhancer_enabled=False, enhancer_to
|
|
| 121 |
SESSION_HISTORY[session_id] = []
|
| 122 |
|
| 123 |
SESSION_HISTORY[session_id].append({"role": "user", "content": user_text})
|
| 124 |
-
messages = [
|
|
|
|
| 125 |
|
| 126 |
if enhancer_enabled:
|
| 127 |
messages.append({"role": "user", "content": f"Enhance response. Tone: {enhancer_tone}. Question: {user_text}"})
|
|
@@ -154,10 +155,16 @@ def handle_pdf_question(question, session_id):
|
|
| 154 |
if session_id not in PDF_CONTENT:
|
| 155 |
return "Document not found. Upload first."
|
| 156 |
chunk = select_relevant_chunk(question, PDF_CONTENT[session_id], PDF_EMBEDS[session_id])
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
assistant_text = groq_chat_completion(messages)
|
| 162 |
# Add snippet highlighting for wow factor
|
| 163 |
assistant_text = f"**Snippet from PDF:**\n{chunk[:200]}...\n\n**Answer:**\n{assistant_text}"
|
|
@@ -203,9 +210,15 @@ def handle_image_question(question, session_id):
|
|
| 203 |
return "Image not found. Upload first."
|
| 204 |
chunk = select_relevant_chunk(question, IMAGE_TEXT[session_id], IMAGE_EMBEDS[session_id])
|
| 205 |
messages = [
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
assistant_text = groq_chat_completion(messages)
|
| 210 |
assistant_text = f"**Snippet from Image:**\n{chunk[:200]}...\n\n**Answer:**\n{assistant_text}"
|
| 211 |
if session_id not in SESSION_HISTORY:
|
|
|
|
| 121 |
SESSION_HISTORY[session_id] = []
|
| 122 |
|
| 123 |
SESSION_HISTORY[session_id].append({"role": "user", "content": user_text})
|
| 124 |
+
messages = [
|
| 125 |
+
{"role": "system", "content": "You are a helpful AI assistant. ALWAYS respond in English only, regardless of the user's language or the input language."}] + SESSION_HISTORY[session_id]
|
| 126 |
|
| 127 |
if enhancer_enabled:
|
| 128 |
messages.append({"role": "user", "content": f"Enhance response. Tone: {enhancer_tone}. Question: {user_text}"})
|
|
|
|
| 155 |
if session_id not in PDF_CONTENT:
|
| 156 |
return "Document not found. Upload first."
|
| 157 |
chunk = select_relevant_chunk(question, PDF_CONTENT[session_id], PDF_EMBEDS[session_id])
|
| 158 |
+
messages = [
|
| 159 |
+
{
|
| 160 |
+
"role": "system",
|
| 161 |
+
"content": "You are a helpful assistant summarizing PDF content. ALWAYS respond in English only, regardless of the user's language."
|
| 162 |
+
},
|
| 163 |
+
{
|
| 164 |
+
"role": "user",
|
| 165 |
+
"content": f"PDF chunk:\n{chunk}\n\nQuestion: {question}"
|
| 166 |
+
}
|
| 167 |
+
]
|
| 168 |
assistant_text = groq_chat_completion(messages)
|
| 169 |
# Add snippet highlighting for wow factor
|
| 170 |
assistant_text = f"**Snippet from PDF:**\n{chunk[:200]}...\n\n**Answer:**\n{assistant_text}"
|
|
|
|
| 210 |
return "Image not found. Upload first."
|
| 211 |
chunk = select_relevant_chunk(question, IMAGE_TEXT[session_id], IMAGE_EMBEDS[session_id])
|
| 212 |
messages = [
|
| 213 |
+
{
|
| 214 |
+
"role": "system",
|
| 215 |
+
"content": "You are a helpful assistant summarizing image text. ALWAYS respond in English only, regardless of the user's language."
|
| 216 |
+
},
|
| 217 |
+
{
|
| 218 |
+
"role": "user",
|
| 219 |
+
"content": f"Image chunk:\n{chunk}\n\nQuestion: {question}"
|
| 220 |
+
}
|
| 221 |
+
]
|
| 222 |
assistant_text = groq_chat_completion(messages)
|
| 223 |
assistant_text = f"**Snippet from Image:**\n{chunk[:200]}...\n\n**Answer:**\n{assistant_text}"
|
| 224 |
if session_id not in SESSION_HISTORY:
|