Shreyas94 commited on
Commit
b67aee1
·
verified ·
1 Parent(s): 1d481ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -6
app.py CHANGED
@@ -1,23 +1,36 @@
1
  import os
2
  import gradio as gr
3
  from groq import Groq
 
 
4
 
5
- # Init Groq client
6
- client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
7
 
8
- # This now takes 3 args: message, history, and additional_input
 
 
 
 
 
 
 
9
  def chat_inference(message, history, example_prompt):
10
  try:
 
11
  response = client.chat.completions.create(
12
  messages=[{"role": "user", "content": message}],
13
  model="compound-beta"
14
  )
15
  reply = response.choices[0].message.content
 
16
  except Exception as e:
17
- reply = f"⚠️ Error: {str(e)}"
 
 
18
  return reply
19
 
20
- # Optional example input (can remove if not needed)
21
  additional_inputs = [
22
  gr.Textbox(label="🔍 Example Prompt", value="What were the main highlights from the latest Apple keynote?")
23
  ]
@@ -29,7 +42,7 @@ chat_interface = gr.ChatInterface(
29
  title="🔍 AI-Powered Real-Time Search with Groq",
30
  description="Ask anything that requires real-time info — powered by Groq’s `compound-beta` model.",
31
  theme="default",
32
- type="messages", # Correct value!
33
  )
34
 
35
  if __name__ == "__main__":
 
1
  import os
2
  import gradio as gr
3
  from groq import Groq
4
+ import traceback
5
+ import logging
6
 
7
+ # Setup logging
8
+ logging.basicConfig(filename="error.log", level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s")
9
 
10
+ # Check if API key is loaded
11
+ api_key = os.environ.get("GROQ_API_KEY")
12
+ if not api_key:
13
+ logging.error("Missing GROQ_API_KEY environment variable.")
14
+
15
+ client = Groq(api_key=api_key)
16
+
17
+ # Function with error logging
18
  def chat_inference(message, history, example_prompt):
19
  try:
20
+ logging.debug(f"User message: {message}")
21
  response = client.chat.completions.create(
22
  messages=[{"role": "user", "content": message}],
23
  model="compound-beta"
24
  )
25
  reply = response.choices[0].message.content
26
+ logging.debug(f"Groq reply: {reply}")
27
  except Exception as e:
28
+ error_details = traceback.format_exc()
29
+ logging.error(f"Error during Groq API call:\n{error_details}")
30
+ reply = f"⚠️ Error: Connection error or API issue.\n\nSee logs in `error.log` for more info."
31
  return reply
32
 
33
+ # Optional input
34
  additional_inputs = [
35
  gr.Textbox(label="🔍 Example Prompt", value="What were the main highlights from the latest Apple keynote?")
36
  ]
 
42
  title="🔍 AI-Powered Real-Time Search with Groq",
43
  description="Ask anything that requires real-time info — powered by Groq’s `compound-beta` model.",
44
  theme="default",
45
+ type="messages", # Correct format
46
  )
47
 
48
  if __name__ == "__main__":