Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# app.py - COMPLETE, FINAL, 100% WORKING VERSION (November 21, 2025)
|
| 2 |
-
# Your original UI + PDF upload fixed + Voice on every answer + Emojis removed from voice + Groq key
|
| 3 |
import os
|
| 4 |
import re
|
| 5 |
import logging
|
|
@@ -29,25 +29,24 @@ class AgenticRAGAgent:
|
|
| 29 |
self.index = None
|
| 30 |
self.embedder = SentenceTransformer('all-MiniLM-L6-v2')
|
| 31 |
|
| 32 |
-
#
|
|
|
|
|
|
|
| 33 |
self.groq = None
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
logger.info("Groq API key loaded and working!")
|
| 41 |
-
except Exception as e:
|
| 42 |
-
logger.error(f"Groq init error: {e}")
|
| 43 |
|
| 44 |
# Remove emojis completely from voice
|
| 45 |
def remove_emojis(self, text: str) -> str:
|
| 46 |
-
emoji_pattern = re.compile("["
|
| 47 |
-
u"\U0001F600-\U0001F64F"
|
| 48 |
-
u"\U0001F300-\U0001F5FF"
|
| 49 |
-
u"\U0001F680-\U0001F6FF"
|
| 50 |
-
u"\U0001F1E0-\U0001F1FF"
|
| 51 |
u"\U00002702-\U000027B0"
|
| 52 |
u"\U000024C2-\U0001F251"
|
| 53 |
"]+", flags=re.UNICODE)
|
|
@@ -147,11 +146,11 @@ class AgenticRAGAgent:
|
|
| 147 |
prompt = f"Context from documents:\n{context}\n\nQuestion: {question}\nAnswer clearly and accurately:"
|
| 148 |
|
| 149 |
if not self.groq:
|
| 150 |
-
reply = "GROQ_API_KEY is missing or invalid.
|
| 151 |
else:
|
| 152 |
try:
|
| 153 |
resp = self.groq.chat.completions.create(
|
| 154 |
-
model="llama-3.
|
| 155 |
messages=[{"role": "user", "content": prompt}],
|
| 156 |
temperature=0.3,
|
| 157 |
max_tokens=700
|
|
@@ -207,4 +206,4 @@ def create_interface():
|
|
| 207 |
|
| 208 |
if __name__ == "__main__":
|
| 209 |
app = create_interface()
|
| 210 |
-
app.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
# app.py - COMPLETE, FINAL, 100% WORKING VERSION (November 21, 2025)
|
| 2 |
+
# Your original UI + PDF upload fixed + Voice on every answer + Emojis removed from voice + Groq key hardcoded
|
| 3 |
import os
|
| 4 |
import re
|
| 5 |
import logging
|
|
|
|
| 29 |
self.index = None
|
| 30 |
self.embedder = SentenceTransformer('all-MiniLM-L6-v2')
|
| 31 |
|
| 32 |
+
# ==========================
|
| 33 |
+
# Hardcoded Groq API key
|
| 34 |
+
# ==========================
|
| 35 |
self.groq = None
|
| 36 |
+
if GROQ_OK:
|
| 37 |
+
try:
|
| 38 |
+
self.groq = Groq(api_key="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") # <-- Replace with your new key
|
| 39 |
+
logger.info("Groq API key loaded and working!")
|
| 40 |
+
except Exception as e:
|
| 41 |
+
logger.error(f"Groq init error: {e}")
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
# Remove emojis completely from voice
|
| 44 |
def remove_emojis(self, text: str) -> str:
|
| 45 |
+
emoji_pattern = re.compile("["
|
| 46 |
+
u"\U0001F600-\U0001F64F"
|
| 47 |
+
u"\U0001F300-\U0001F5FF"
|
| 48 |
+
u"\U0001F680-\U0001F6FF"
|
| 49 |
+
u"\U0001F1E0-\U0001F1FF"
|
| 50 |
u"\U00002702-\U000027B0"
|
| 51 |
u"\U000024C2-\U0001F251"
|
| 52 |
"]+", flags=re.UNICODE)
|
|
|
|
| 146 |
prompt = f"Context from documents:\n{context}\n\nQuestion: {question}\nAnswer clearly and accurately:"
|
| 147 |
|
| 148 |
if not self.groq:
|
| 149 |
+
reply = "GROQ_API_KEY is missing or invalid."
|
| 150 |
else:
|
| 151 |
try:
|
| 152 |
resp = self.groq.chat.completions.create(
|
| 153 |
+
model="llama-3.3-70b-versatile", # <-- Updated supported model
|
| 154 |
messages=[{"role": "user", "content": prompt}],
|
| 155 |
temperature=0.3,
|
| 156 |
max_tokens=700
|
|
|
|
| 206 |
|
| 207 |
if __name__ == "__main__":
|
| 208 |
app = create_interface()
|
| 209 |
+
app.launch(server_name="0.0.0.0", server_port=7860)
|