File size: 11,353 Bytes
7c94330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fad6406
7c94330
 
 
 
 
 
 
 
fad6406
7c94330
 
fad6406
 
 
 
 
 
 
 
 
 
 
7c94330
 
fad6406
7c94330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fad6406
 
7c94330
 
 
 
 
 
 
 
 
fad6406
7c94330
 
 
 
d519998
7c94330
 
fad6406
7c94330
fad6406
7c94330
 
 
 
 
 
 
 
fad6406
7c94330
 
 
 
fad6406
7c94330
 
 
 
 
 
 
 
 
fad6406
7c94330
fad6406
7c94330
fad6406
 
7c94330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fad6406
7c94330
 
 
fad6406
 
7c94330
fad6406
7c94330
fad6406
7c94330
fad6406
7c94330
 
 
 
 
 
 
 
fad6406
 
 
 
 
7c94330
 
 
 
 
 
 
 
 
 
 
 
 
 
fad6406
7c94330
 
 
 
 
 
 
 
fad6406
7c94330
 
8cbbfee
d519998
ad771f5
a43224a
d519998
 
 
 
ad771f5
d519998
ad771f5
 
 
 
 
 
 
 
 
 
d519998
 
ad771f5
 
 
 
 
d519998
ad771f5
 
d519998
 
 
 
 
 
 
 
 
 
a43224a
d519998
2389366
d519998
 
 
 
 
 
 
 
 
 
a43224a
d519998
a43224a
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
from __future__ import annotations
from typing import Iterable
import gradio as gr
from gradio.themes.base import Base
from gradio.themes.utils import colors, fonts, sizes

class Neopy(Base):
    def __init__(
        self,
        *,
        primary_hue: colors.Color | str = colors.neutral,
        secondary_hue: colors.Color | str = colors.neutral,
        neutral_hue: colors.Color | str = colors.neutral,
        spacing_size: sizes.Size | str = sizes.spacing_md,
        radius_size: sizes.Size | str = sizes.radius_md,
        text_size: sizes.Size | str = sizes.text_lg,
        font: fonts.Font | str | Iterable[fonts.Font | str] = (
            "Syne V",
            fonts.GoogleFont("Syne"),
            "ui-sans-serif",
            "system-ui",
        ),
        font_mono: fonts.Font | str | Iterable[fonts.Font | str] = (
            "ui-monospace",
            fonts.GoogleFont("Nunito Sans"),
        ),
    ):
        super().__init__(
            primary_hue=primary_hue,
            secondary_hue=secondary_hue,
            neutral_hue=neutral_hue,
            spacing_size=spacing_size,
            radius_size=radius_size,
            text_size=text_size,
            font=font,
            font_mono=font_mono,
        )
        self.name = ("Neopy",)
        # Secondary palette (red, used for errors/warnings)
        self.secondary_100 = ("#b80000",)
        self.secondary_200 = ("#ff6b6b",)
        self.secondary_300 = ("#ff5252",)
        self.secondary_400 = ("#ff3232",)
        self.secondary_50 = ("#bd5151",)
        self.secondary_500 = ("#d31c1c",)
        self.secondary_600 = ("#eb2525",)
        self.secondary_700 = ("#d81d1d",)
        self.secondary_800 = ("#1e40af",)  # Note: This seems out of place (blue in red palette), but kept as is
        self.secondary_900 = ("#af1e1e",)
        self.secondary_950 = ("#601d1d",)
        # New primary palette (blue, for main accents)
        self.primary_50 = ("#eff6ff",)
        self.primary_100 = ("#dbeafe",)
        self.primary_200 = ("#bfdbfe",)
        self.primary_300 = ("#93c5fd",)
        self.primary_400 = ("#60a5fa",)
        self.primary_500 = ("#3b82f6",)
        self.primary_600 = ("#2563eb",)
        self.primary_700 = ("#1d4ed8",)
        self.primary_800 = ("#1e40af",)
        self.primary_900 = ("#1e3a8a",)

        super().set(
            # Backgrounds
            background_fill_primary="#110F0F",
            background_fill_primary_dark="#110F0F",
            background_fill_secondary="#110F0F",
            background_fill_secondary_dark="#110F0F",
            block_background_fill="*neutral_800",
            block_background_fill_dark="*neutral_800",
            block_border_color="*border_color_primary",
            block_border_width="1px",
            block_info_text_color="*body_text_color_subdued",
            block_info_text_size="*text_sm",
            block_info_text_weight="400",
            block_label_background_fill="*background_fill_primary",
            block_label_background_fill_dark="*background_fill_secondary",
            block_label_border_color="*border_color_primary",
            block_label_border_width="1px",
            block_label_margin="0",
            block_label_padding="*spacing_sm *spacing_lg",
            block_label_radius="calc(*radius_lg - 1px) 0 calc(*radius_lg - 1px) 0",
            block_label_right_radius="0 calc(*radius_lg - 1px) 0 calc(*radius_lg - 1px)",
            block_label_shadow="*block_shadow",
            block_label_text_color="*body_text_color",  # Fixed to white for visibility
            block_label_text_color_dark="*body_text_color",
            block_label_text_weight="400",
            block_padding="*spacing_xl",
            block_radius="*radius_md",
            block_shadow="none",
            block_title_background_fill="rgb(255,255,255)",
            block_title_border_color="none",
            block_title_border_width="0px",
            block_title_padding="*block_label_padding",
            block_title_radius="*block_label_radius",
            block_title_text_color="#110F0F",  # Dark text on white background
            block_title_text_size="*text_md",
            block_title_text_weight="600",
            body_background_fill="#110F0F",
            body_text_color="white",
            body_text_color_subdued="#cecece",
            body_text_size="*text_md",
            body_text_weight="400",
            border_color_accent="*primary_500",
            border_color_primary="*neutral_800",
            # Buttons
            button_border_width="*input_border_width",
            button_cancel_background_fill="*button_secondary_background_fill",
            button_cancel_border_color="*button_secondary_border_color",
            button_cancel_text_color="#110F0F",
            button_large_padding="*spacing_lg calc(2 * *spacing_lg)",
            button_large_radius="*radius_lg",
            button_large_text_size="*text_lg",
            button_large_text_weight="600",
            button_primary_background_fill="*primary_600",  # Blue buttons
            button_primary_background_fill_hover="*primary_500",
            button_primary_border_color="*primary_500",
            button_primary_border_color_hover="*primary_400",
            button_primary_text_color="white",
            button_primary_text_color_hover="white",  # Changed for contrast on blue
            button_secondary_background_fill="transparent",
            button_secondary_background_fill_hover="*neutral_800",
            button_secondary_border_color="*neutral_700",
            button_secondary_text_color="white",
            button_small_padding="*spacing_sm calc(2 * *spacing_sm)",
            button_small_radius="*radius_lg",
            button_small_text_size="*text_md",
            button_small_text_weight="400",
            button_transition="0.3s ease all",
            # Checkboxes
            checkbox_background_color="*neutral_700",
            checkbox_background_color_selected="*primary_500",  # Blue when selected
            checkbox_border_color="*neutral_700",
            checkbox_border_color_focus="*primary_500",
            checkbox_border_color_selected="*primary_500",
            checkbox_border_radius="*radius_sm",
            checkbox_border_width="*input_border_width",
            checkbox_check="url(\"data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e\")",
            checkbox_label_background_fill="transparent",
            checkbox_label_border_color="transparent",
            checkbox_label_border_width="transparent",
            checkbox_label_gap="*spacing_lg",
            checkbox_label_padding="*spacing_md calc(2 * *spacing_md)",
            checkbox_label_shadow="none",
            checkbox_label_text_color="*body_text_color",
            checkbox_label_text_size="*text_md",
            checkbox_label_text_weight="400",
            checkbox_shadow="*input_shadow",
            color_accent="*primary_500",
            color_accent_soft="*primary_50",
            container_radius="*radius_xl",
            embed_radius="*radius_lg",
            # Errors
            error_background_fill="*background_fill_primary",
            error_border_color="*border_color_primary",
            error_border_width="1px",
            error_text_color="*secondary_700",  # Red for errors
            error_text_color_dark="*secondary_600",
            form_gap_width="0px",
            # Inputs
            input_background_fill="*neutral_900",
            input_background_fill_focus="*primary_50",  # Light blue when focused
            input_border_color="*neutral_700",
            input_border_color_focus="*primary_500",  # Blue border when focused
            input_border_width="1px",
            input_padding="*spacing_xl",
            input_placeholder_color="*neutral_500",
            input_radius="*radius_lg",
            input_shadow="none",
            input_text_size="*text_md",
            input_text_weight="400",
            layout_gap="*spacing_xxl",
            # Links
            link_text_color="*primary_500",  # Blue links
            link_text_color_active="*primary_500",
            link_text_color_hover="*primary_400",
            link_text_color_visited="*primary_600",
            loader_color="*color_accent",
            panel_background_fill="*background_fill_secondary",
            panel_border_color="*border_color_primary",
            panel_border_width="1px",
            prose_header_text_weight="600",
            prose_text_size="*text_md",
            prose_text_weight="400",
            radio_circle="url(\"data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3ccircle cx='8' cy='8' r='3'/%3e%3c/svg%3e\")",
            section_header_text_size="*text_md",
            section_header_text_weight="400",
            shadow_drop="rgba(0,0,0,0.05) 0px 1px 2px 0px",
            shadow_drop_lg="0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1)",
            shadow_inset="rgba(0,0,0,0.05) 0px 2px 4px 0px inset",
            shadow_spread="3px",
            slider_color="*primary_500",  # Blue slider
            stat_background_fill="*primary_500",
            table_border_color="*neutral_700",
            table_even_background_fill="*neutral_950",
            table_odd_background_fill="*neutral_900",
            table_radius="*radius_lg",
            table_row_focus="*color_accent_soft",
        )

theme = Neopy()



import os
import subprocess

def download_audio(youtube_url):
    output_dir = "downloads"
    os.makedirs(output_dir, exist_ok=True)
    output_file = os.path.join(output_dir, "audio.%(ext)s")
    audio_file = os.path.join(output_dir, "audio.mp3")

    command = [
        "yt-dlp",
        "--format", "bestaudio/best",
        "--output", output_file,
        "--cookies", "./ytdlp.txt",
        "--extract-audio",
        "--audio-format", "mp3",
        "--audio-quality", "192K",
        youtube_url
    ]

    try:
        result = subprocess.run(command, capture_output=True, text=True)
        if result.returncode == 0 and os.path.exists(audio_file):
            return audio_file, "Audio downloaded successfully."
        else:
            return None, f"Error: {result.stderr.strip() or 'Unknown error.'}"
    except Exception as e:
        return None, f"Exception during download: {str(e)}"


# Chatbot function to display audio and message
def chatbot_response(youtube_url):
    audio_file, message = download_audio(youtube_url)
    if audio_file:
        return [(message, gr.Audio(audio_file))]
    else:
        return [(message, None)]

# Gradio Blocks UI
with gr.Blocks(theme=theme) as demo:
    gr.Markdown("# YouTube Audio Downloader Chatbot")
    with gr.Row(equal_height=True):
        youtube_input = gr.Textbox(label="Enter YouTube URL", placeholder="https://www.youtube.com/watch?v=...")
        submit_button = gr.Button("Download and Display")
    
    chatbot = gr.Chatbot(label="Chatbot Output")
    
    submit_button.click(
        fn=chatbot_response,
        inputs=youtube_input,
        outputs=chatbot
    )

# Launch the Gradio app
demo.launch()