ArceusInception commited on
Commit
707fafa
·
verified ·
1 Parent(s): dffd221

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -16
app.py CHANGED
@@ -1,29 +1,20 @@
1
  import gradio as gr
2
  import os
3
  import requests
 
4
 
5
  def preprocess_city_name_and_generate_insight(city_name):
6
  api_key = os.getenv("GROQ_API_KEY")
7
  if not api_key:
8
  return city_name, "GROQ API key is not set in the environment variables."
9
-
10
- url = "https://api.example.com/generate_insight" # Hypothetical URL
11
- headers = {
12
- "Authorization": f"Bearer {api_key}",
13
- "Content-Type": "application/json"
14
- }
15
- data = {
16
- "model": "llama3-70b-8192",
17
- "prompt": f"Generate a short, interesting fact about {city_name} in less than 10 words."
18
- }
19
 
20
  try:
21
- response = requests.post(url, json=data, headers=headers)
22
- if response.status_code == 200:
23
- result = response.json()
24
- insight = result.get('text', "No insight generated.").strip()
25
- else:
26
- insight = "Failed to generate insight due to API error."
27
  except Exception as e:
28
  print(f"Error generating insight: {str(e)}")
29
  insight = "Could not generate insight due to an error."
 
1
  import gradio as gr
2
  import os
3
  import requests
4
+ from groq import Groq
5
 
6
  def preprocess_city_name_and_generate_insight(city_name):
7
  api_key = os.getenv("GROQ_API_KEY")
8
  if not api_key:
9
  return city_name, "GROQ API key is not set in the environment variables."
 
 
 
 
 
 
 
 
 
 
10
 
11
  try:
12
+ client = Groq(api_key=api_key)
13
+
14
+ prompt = f"Generate a short, interesting fact about {city_name} in less than 10 words."
15
+ result = client.query(prompt=prompt, model_id="llama3-70b-8192") # Adjust parameters as necessary
16
+
17
+ insight = result.get('generated_text', "No insight generated.").strip()
18
  except Exception as e:
19
  print(f"Error generating insight: {str(e)}")
20
  insight = "Could not generate insight due to an error."