Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 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."
|