Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
# Audio URLs
|
4 |
AUDIO_URLS = {
|
@@ -11,7 +13,17 @@ AUDIO_URLS = {
|
|
11 |
}
|
12 |
|
13 |
def fetch_audio(category):
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
def create_news_dashboard():
|
17 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
@@ -22,41 +34,41 @@ def create_news_dashboard():
|
|
22 |
gr.Markdown("### π° Money News")
|
23 |
money_audio = gr.Audio(interactive=False, type="filepath")
|
24 |
money_btn = gr.Button("Play Money News")
|
25 |
-
money_btn.click(fn=fetch_audio, inputs=
|
26 |
|
27 |
with gr.Column(scale=1):
|
28 |
gr.Markdown("### π Geopolitical News")
|
29 |
geo_audio = gr.Audio(interactive=False, type="filepath")
|
30 |
geo_btn = gr.Button("Play Geopolitical News")
|
31 |
-
geo_btn.click(fn=fetch_audio, inputs=
|
32 |
|
33 |
with gr.Column(scale=1):
|
34 |
gr.Markdown("### π World News")
|
35 |
world_audio = gr.Audio(interactive=False, type="filepath")
|
36 |
world_btn = gr.Button("Play World News")
|
37 |
-
world_btn.click(fn=fetch_audio, inputs=
|
38 |
|
39 |
with gr.Row():
|
40 |
with gr.Column(scale=1):
|
41 |
gr.Markdown("### π Entertainment")
|
42 |
ent_audio = gr.Audio(interactive=False, type="filepath")
|
43 |
ent_btn = gr.Button("Play Entertainment News")
|
44 |
-
ent_btn.click(fn=fetch_audio, inputs=
|
45 |
|
46 |
with gr.Column(scale=1):
|
47 |
gr.Markdown("### π₯ Health News")
|
48 |
health_audio = gr.Audio(interactive=False, type="filepath")
|
49 |
health_btn = gr.Button("Play Health News")
|
50 |
-
health_btn.click(fn=fetch_audio, inputs=
|
51 |
|
52 |
with gr.Column(scale=1):
|
53 |
gr.Markdown("### π Sports News")
|
54 |
sports_audio = gr.Audio(interactive=False, type="filepath")
|
55 |
sports_btn = gr.Button("Play Sports News")
|
56 |
-
sports_btn.click(fn=fetch_audio, inputs=
|
57 |
|
58 |
return demo
|
59 |
|
60 |
if __name__ == "__main__":
|
61 |
demo = create_news_dashboard()
|
62 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import tempfile
|
4 |
|
5 |
# Audio URLs
|
6 |
AUDIO_URLS = {
|
|
|
13 |
}
|
14 |
|
15 |
def fetch_audio(category):
|
16 |
+
# Fetch audio from URL and save it to a temporary file
|
17 |
+
url = AUDIO_URLS[category]
|
18 |
+
response = requests.get(url)
|
19 |
+
response.raise_for_status() # Ensure the request was successful
|
20 |
+
|
21 |
+
# Save to a temporary file
|
22 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".wav")
|
23 |
+
temp_file.write(response.content)
|
24 |
+
temp_file.close()
|
25 |
+
|
26 |
+
return temp_file.name # Return the path to the temporary file
|
27 |
|
28 |
def create_news_dashboard():
|
29 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
|
34 |
gr.Markdown("### π° Money News")
|
35 |
money_audio = gr.Audio(interactive=False, type="filepath")
|
36 |
money_btn = gr.Button("Play Money News")
|
37 |
+
money_btn.click(fn=fetch_audio, inputs="Money", outputs=money_audio)
|
38 |
|
39 |
with gr.Column(scale=1):
|
40 |
gr.Markdown("### π Geopolitical News")
|
41 |
geo_audio = gr.Audio(interactive=False, type="filepath")
|
42 |
geo_btn = gr.Button("Play Geopolitical News")
|
43 |
+
geo_btn.click(fn=fetch_audio, inputs="Geopolitical", outputs=geo_audio)
|
44 |
|
45 |
with gr.Column(scale=1):
|
46 |
gr.Markdown("### π World News")
|
47 |
world_audio = gr.Audio(interactive=False, type="filepath")
|
48 |
world_btn = gr.Button("Play World News")
|
49 |
+
world_btn.click(fn=fetch_audio, inputs="World", outputs=world_audio)
|
50 |
|
51 |
with gr.Row():
|
52 |
with gr.Column(scale=1):
|
53 |
gr.Markdown("### π Entertainment")
|
54 |
ent_audio = gr.Audio(interactive=False, type="filepath")
|
55 |
ent_btn = gr.Button("Play Entertainment News")
|
56 |
+
ent_btn.click(fn=fetch_audio, inputs="Entertainment", outputs=ent_audio)
|
57 |
|
58 |
with gr.Column(scale=1):
|
59 |
gr.Markdown("### π₯ Health News")
|
60 |
health_audio = gr.Audio(interactive=False, type="filepath")
|
61 |
health_btn = gr.Button("Play Health News")
|
62 |
+
health_btn.click(fn=fetch_audio, inputs="Health", outputs=health_audio)
|
63 |
|
64 |
with gr.Column(scale=1):
|
65 |
gr.Markdown("### π Sports News")
|
66 |
sports_audio = gr.Audio(interactive=False, type="filepath")
|
67 |
sports_btn = gr.Button("Play Sports News")
|
68 |
+
sports_btn.click(fn=fetch_audio, inputs="Sports", outputs=sports_audio)
|
69 |
|
70 |
return demo
|
71 |
|
72 |
if __name__ == "__main__":
|
73 |
demo = create_news_dashboard()
|
74 |
+
demo.launch()
|