Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,10 @@
|
|
1 |
-
import os, uuid, gradio as gr,
|
2 |
from PIL import Image
|
3 |
import whisper
|
4 |
|
5 |
-
|
|
|
|
|
6 |
|
7 |
def extract_text_from_file(file):
|
8 |
if file is None: return ""
|
@@ -34,13 +36,25 @@ def transcribe_audio(audio_path):
|
|
34 |
|
35 |
def chat_response(history, message):
|
36 |
try:
|
|
|
|
|
|
|
|
|
37 |
messages = [{"role": "system", "content": "You are Neobot, a helpful assistant."}]
|
38 |
-
for role, content in history:
|
|
|
39 |
messages.append({"role": "user", "content": message})
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
except Exception as e:
|
43 |
-
return f"
|
44 |
|
45 |
def process_input(msg, file, audio, history):
|
46 |
file_text = extract_text_from_file(file) if file else ""
|
|
|
1 |
+
import os, uuid, requests, gradio as gr, pdfplumber, docx, pandas as pd
|
2 |
from PIL import Image
|
3 |
import whisper
|
4 |
|
5 |
+
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
6 |
+
GROQ_API_URL = "https://api.groq.com/openai/v1/chat/completions"
|
7 |
+
MODEL_NAME = "llama3-8b-8192" # Update if using a different model
|
8 |
|
9 |
def extract_text_from_file(file):
|
10 |
if file is None: return ""
|
|
|
36 |
|
37 |
def chat_response(history, message):
|
38 |
try:
|
39 |
+
headers = {
|
40 |
+
"Authorization": f"Bearer {GROQ_API_KEY}",
|
41 |
+
"Content-Type": "application/json"
|
42 |
+
}
|
43 |
messages = [{"role": "system", "content": "You are Neobot, a helpful assistant."}]
|
44 |
+
for role, content in history:
|
45 |
+
messages.append({"role": role, "content": content})
|
46 |
messages.append({"role": "user", "content": message})
|
47 |
+
|
48 |
+
payload = {
|
49 |
+
"model": MODEL_NAME,
|
50 |
+
"messages": messages
|
51 |
+
}
|
52 |
+
|
53 |
+
response = requests.post(GROQ_API_URL, headers=headers, json=payload)
|
54 |
+
reply = response.json()["choices"][0]["message"]["content"]
|
55 |
+
return reply.strip()
|
56 |
except Exception as e:
|
57 |
+
return f"Groq response failed: {e}"
|
58 |
|
59 |
def process_input(msg, file, audio, history):
|
60 |
file_text = extract_text_from_file(file) if file else ""
|