Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,50 @@
|
|
| 1 |
-
# Tech Trends Curator with Audio
|
| 2 |
|
|
|
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
-
|
| 5 |
from gtts import gTTS
|
| 6 |
-
import uuid
|
| 7 |
-
import os
|
| 8 |
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
)
|
| 18 |
}
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
response =
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
)
|
| 26 |
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
#
|
| 30 |
tts = gTTS(output_text)
|
| 31 |
filename = f"/tmp/{uuid.uuid4()}.mp3"
|
| 32 |
tts.save(filename)
|
| 33 |
|
| 34 |
return output_text, filename
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
|
| 38 |
fn=get_tech_trends_with_audio,
|
| 39 |
inputs=gr.Textbox(placeholder="Ask for top trends, tools, or fake news", label="Your Question"),
|
| 40 |
outputs=[
|
|
@@ -51,5 +61,5 @@ interface = gr.Interface(
|
|
| 51 |
theme="soft"
|
| 52 |
)
|
| 53 |
|
| 54 |
-
# Launch
|
| 55 |
-
|
|
|
|
| 1 |
+
# Tech Trends Curator with Audio (Hugging Face Compatible)
|
| 2 |
|
| 3 |
+
import os
|
| 4 |
+
import uuid
|
| 5 |
import gradio as gr
|
| 6 |
+
import requests
|
| 7 |
from gtts import gTTS
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
# Fetch API key from environment
|
| 10 |
+
GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
|
| 11 |
|
| 12 |
+
# Function to query Groq LLM via REST API
|
| 13 |
+
def query_groq(user_input):
|
| 14 |
+
url = "https://api.groq.com/openai/v1/chat/completions"
|
| 15 |
+
headers = {
|
| 16 |
+
"Authorization": f"Bearer {GROQ_API_KEY}",
|
| 17 |
+
"Content-Type": "application/json"
|
|
|
|
| 18 |
}
|
| 19 |
|
| 20 |
+
data = {
|
| 21 |
+
"model": "llama3-8b-8192",
|
| 22 |
+
"messages": [
|
| 23 |
+
{"role": "system", "content": (
|
| 24 |
+
"You are a tech trend curator. Summarize the latest AI tools, GitHub projects, "
|
| 25 |
+
"and startup news in an engaging tone. If asked for fake/funny trends, be creative and witty."
|
| 26 |
+
)},
|
| 27 |
+
{"role": "user", "content": user_input}
|
| 28 |
+
]
|
| 29 |
+
}
|
| 30 |
|
| 31 |
+
response = requests.post(url, headers=headers, json=data)
|
| 32 |
+
result = response.json()
|
| 33 |
+
return result["choices"][0]["message"]["content"]
|
|
|
|
| 34 |
|
| 35 |
+
# Main function for chatbot + audio generation
|
| 36 |
+
def get_tech_trends_with_audio(user_input, history):
|
| 37 |
+
output_text = query_groq(user_input)
|
| 38 |
|
| 39 |
+
# Generate audio
|
| 40 |
tts = gTTS(output_text)
|
| 41 |
filename = f"/tmp/{uuid.uuid4()}.mp3"
|
| 42 |
tts.save(filename)
|
| 43 |
|
| 44 |
return output_text, filename
|
| 45 |
|
| 46 |
+
# Gradio interface
|
| 47 |
+
demo = gr.Interface(
|
| 48 |
fn=get_tech_trends_with_audio,
|
| 49 |
inputs=gr.Textbox(placeholder="Ask for top trends, tools, or fake news", label="Your Question"),
|
| 50 |
outputs=[
|
|
|
|
| 61 |
theme="soft"
|
| 62 |
)
|
| 63 |
|
| 64 |
+
# Launch app
|
| 65 |
+
demo.launch(share=True)
|