Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,9 +7,10 @@ import time
|
|
| 7 |
import torch
|
| 8 |
import requests
|
| 9 |
import json
|
|
|
|
| 10 |
|
| 11 |
# Groq API Configuration
|
| 12 |
-
GROQ_API_KEY = "
|
| 13 |
GROQ_API_URL = "https://api.groq.com/openai/v1/chat/completions"
|
| 14 |
|
| 15 |
# Load processor
|
|
@@ -31,23 +32,23 @@ def classify_sign(image):
|
|
| 31 |
prediction = inputs['pixel_values'].argmax().item()
|
| 32 |
gesture = sign_labels.get(prediction % len(sign_labels), "Unknown Sign")
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
|
| 52 |
# Streamlit UI
|
| 53 |
|
|
|
|
| 7 |
import torch
|
| 8 |
import requests
|
| 9 |
import json
|
| 10 |
+
import os
|
| 11 |
|
| 12 |
# Groq API Configuration
|
| 13 |
+
GROQ_API_KEY = os.getenv("HF_GROQ_API_KEY") # Fetch key from Hugging Face secrets
|
| 14 |
GROQ_API_URL = "https://api.groq.com/openai/v1/chat/completions"
|
| 15 |
|
| 16 |
# Load processor
|
|
|
|
| 32 |
prediction = inputs['pixel_values'].argmax().item()
|
| 33 |
gesture = sign_labels.get(prediction % len(sign_labels), "Unknown Sign")
|
| 34 |
|
| 35 |
+
if GROQ_API_KEY:
|
| 36 |
+
response = requests.post(
|
| 37 |
+
GROQ_API_URL,
|
| 38 |
+
headers={
|
| 39 |
+
"Content-Type": "application/json",
|
| 40 |
+
"Authorization": f"Bearer {GROQ_API_KEY}"
|
| 41 |
+
},
|
| 42 |
+
json={
|
| 43 |
+
"model": "llama-3.3-70b-versatile",
|
| 44 |
+
"messages": [{"role": "user", "content": f"Refine this detected sign: {gesture}"}]
|
| 45 |
+
}
|
| 46 |
+
)
|
| 47 |
|
| 48 |
+
if response.status_code == 200:
|
| 49 |
+
return response.json()['choices'][0]['message']['content']
|
| 50 |
+
|
| 51 |
+
return gesture
|
| 52 |
|
| 53 |
# Streamlit UI
|
| 54 |
|