AamirMalik commited on
Commit
36716e8
·
verified ·
1 Parent(s): 24ea69d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -17
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 = "your_api_key_here"
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
- # Groq API call for refinement
35
- response = requests.post(
36
- GROQ_API_URL,
37
- headers={
38
- "Content-Type": "application/json",
39
- "Authorization": f"Bearer {GROQ_API_KEY}"
40
- },
41
- json={
42
- "model": "llama-3.3-70b-versatile",
43
- "messages": [{"role": "user", "content": f"Refine this detected sign: {gesture}"}]
44
- }
45
- )
46
 
47
- if response.status_code == 200:
48
- return response.json()['choices'][0]['message']['content']
49
- else:
50
- return gesture
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