File size: 3,803 Bytes
5fa1f64
18abbdd
 
5fa1f64
 
 
 
c9c6cbb
5fa1f64
 
 
 
 
 
c9c6cbb
18abbdd
 
 
 
 
 
 
 
 
 
 
c9c6cbb
5fa1f64
 
1086fa2
5fa1f64
1086fa2
 
5fa1f64
ecfb259
c9c6cbb
476a003
 
5fa1f64
1086fa2
5fa1f64
ecfb259
c9c6cbb
476a003
 
5fa1f64
1086fa2
5fa1f64
ecfb259
c9c6cbb
476a003
 
1086fa2
 
 
5fa1f64
ecfb259
c9c6cbb
476a003
 
5fa1f64
1086fa2
5fa1f64
ecfb259
c9c6cbb
476a003
 
ee84f0a
 
 
ecfb259
ee84f0a
476a003
 
ee84f0a
 
 
 
 
18abbdd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import gradio as gr
import requests
import tempfile

# Audio URLs
AUDIO_URLS = {
    "Money": "https://pub-6dc43089a07d4218adb4b0579b3be0b9.r2.dev/News/News_Money.wav",
    "Geopolitical": "https://pub-6dc43089a07d4218adb4b0579b3be0b9.r2.dev/News/News_Geopolitical.wav", 
    "World": "https://pub-6dc43089a07d4218adb4b0579b3be0b9.r2.dev/News/News_World.wav",
    "Entertainment": "https://pub-6dc43089a07d4218adb4b0579b3be0b9.r2.dev/News/News_Entertainment.wav",
    "Health": "https://pub-6dc43089a07d4218adb4b0579b3be0b9.r2.dev/News/News_Health.wav",
    "Sports": "https://pub-6dc43089a07d4218adb4b0579b3be0b9.r2.dev/News/News_Sports.wav"
}

def fetch_audio(category):
    # Fetch audio from URL and save it to a temporary file
    url = AUDIO_URLS[category]
    response = requests.get(url)
    response.raise_for_status()  # Ensure the request was successful
    
    # Save to a temporary file
    temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".wav")
    temp_file.write(response.content)
    temp_file.close()
    
    return temp_file.name  # Return the path to the temporary file

def create_news_dashboard():
    with gr.Blocks(theme=gr.themes.Soft()) as demo:
        gr.Markdown("# πŸ“» Radio News Dashboard")
        
        with gr.Row():
            with gr.Column(scale=1):
                gr.Markdown("### πŸ’° Money News")
                money_audio = gr.Audio(interactive=False, type="filepath")
                money_btn = gr.Button("Play Money News")
                money_state = gr.State("Money")  # Use gr.State for category
                money_btn.click(fn=fetch_audio, inputs=money_state, outputs=money_audio)
            
            with gr.Column(scale=1):
                gr.Markdown("### 🌍 Geopolitical News")
                geo_audio = gr.Audio(interactive=False, type="filepath")
                geo_btn = gr.Button("Play Geopolitical News")
                geo_state = gr.State("Geopolitical")  # Use gr.State for category
                geo_btn.click(fn=fetch_audio, inputs=geo_state, outputs=geo_audio)
            
            with gr.Column(scale=1):
                gr.Markdown("### 🌐 World News")
                world_audio = gr.Audio(interactive=False, type="filepath")
                world_btn = gr.Button("Play World News")
                world_state = gr.State("World")  # Use gr.State for category
                world_btn.click(fn=fetch_audio, inputs=world_state, outputs=world_audio)
        
        with gr.Row():
            with gr.Column(scale=1):
                gr.Markdown("### 🎭 Entertainment")
                ent_audio = gr.Audio(interactive=False, type="filepath")
                ent_btn = gr.Button("Play Entertainment News")
                ent_state = gr.State("Entertainment")  # Use gr.State for category
                ent_btn.click(fn=fetch_audio, inputs=ent_state, outputs=ent_audio)
            
            with gr.Column(scale=1):
                gr.Markdown("### πŸ₯ Health News")
                health_audio = gr.Audio(interactive=False, type="filepath")
                health_btn = gr.Button("Play Health News")
                health_state = gr.State("Health")  # Use gr.State for category
                health_btn.click(fn=fetch_audio, inputs=health_state, outputs=health_audio)
            
            with gr.Column(scale=1):
                gr.Markdown("### πŸ† Sports News")
                sports_audio = gr.Audio(interactive=False, type="filepath")
                sports_btn = gr.Button("Play Sports News")
                sports_state = gr.State("Sports")  # Use gr.State for category
                sports_btn.click(fn=fetch_audio, inputs=sports_state, outputs=sports_audio)

    return demo

if __name__ == "__main__":
    demo = create_news_dashboard()
    demo.launch()