Affan8 commited on
Commit
d8a48a3
·
verified ·
1 Parent(s): d4f8a9e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -27
app.py CHANGED
@@ -5,21 +5,6 @@ from groq import Groq
5
  # Read API key from Hugging Face Space secret
6
  api_key = os.environ.get("GROQ_API")
7
 
8
- if not api_key:
9
- raise ValueError("No Groq API key found. Please add it as a secret.")
10
-
11
- # Initialize Groq client
12
- client = Groq(api_key=api_key)
13
-
14
- models = client.models.list()
15
-
16
- print("=== AVAILABLE MODELS ===\n")
17
- for m in models.data:
18
- print("-", m.id)
19
-
20
- # You can change this later if needed
21
- MODEL_NAME = "openai/gpt-oss-safeguard-20b"
22
-
23
  def chat_groq(message, history):
24
  """
25
  message: latest user message (string)
@@ -35,20 +20,18 @@ def chat_groq(message, history):
35
  if bot_msg:
36
  messages.append({"role": "user", "content": message})
37
 
38
- completion = client.chat.completions.create(
39
- model=MODEL_NAME,
40
- messages=messages,
41
- max_tokens=1024,
42
- temperature=0.7
43
- )
44
-
45
- # Access the content attribute directly
46
- reply = completion.choices[0].message.content
47
- return reply
48
 
 
 
49
 
50
- except Exception as e:
51
- return f"Error: {e}"
52
 
53
  ui = gr.ChatInterface(
54
  fn=chat_groq,
 
5
  # Read API key from Hugging Face Space secret
6
  api_key = os.environ.get("GROQ_API")
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  def chat_groq(message, history):
9
  """
10
  message: latest user message (string)
 
20
  if bot_msg:
21
  messages.append({"role": "user", "content": message})
22
 
23
+ completion =client.chat.completions.create(
24
+ model= MODEL_NAME,
25
+ messages=messages,
26
+ max_tokens=1024,
27
+ temperature=0.7
28
+ )
 
 
 
 
29
 
30
+ reply = completion.choices[0].message.content
31
+ return reply
32
 
33
+ except Exception as e:
34
+ return f"Error: {e}"
35
 
36
  ui = gr.ChatInterface(
37
  fn=chat_groq,