Maxkillor commited on
Commit
b2ef9bf
·
verified ·
1 Parent(s): 5dae721

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -8
app.py CHANGED
@@ -137,15 +137,92 @@ with gr.Blocks() as demo:
137
  outputs=output_file
138
  )
139
 
140
- # Toggle between light and dark mode
141
- def toggle_theme():
142
- if demo.theme == gr.themes.Default():
143
- demo.theme = gr.themes.Monokai()
144
- else:
145
- demo.theme = gr.themes.Default()
146
- return gr.update()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
 
148
  theme_button = gr.Button("Toggle Theme")
149
- theme_button.click(fn=toggle_theme, outputs=[])
 
 
 
 
150
 
151
  demo.launch()
 
137
  outputs=output_file
138
  )
139
 
140
+
141
+ # theme toggle function
142
+ css = '''
143
+ body.light-mode {
144
+ --bg-color: white;
145
+ --text-color: black;
146
+ }
147
+
148
+ body.dark-mode {
149
+ --bg-color: #2D2D2D;
150
+ --text-color: white;
151
+ }
152
+
153
+ body {
154
+ background-color: var(--bg-color);
155
+ color: var(--text-color);
156
+ }
157
+ '''
158
+
159
+ with gr.Blocks(css=css) as demo:
160
+ theme_state = gr.State('light') # Initialize theme state
161
+
162
+ gr.Markdown("# 📼 Video Transcription and Subtitles Generator")
163
+ gr.Markdown("Upload a video or audio file to get the transcription or subtitles.")
164
+
165
+ with gr.Row():
166
+ file_input = gr.File(
167
+ label="Upload Video or Audio File",
168
+ file_types=['video', 'audio'],
169
+ type='filepath' # Changed to 'filepath'
170
+ )
171
+
172
+ with gr.Row():
173
+ model_size_input = gr.Dropdown(
174
+ label="Select Whisper Model Size",
175
+ choices=model_sizes,
176
+ value='small'
177
+ )
178
+ task_input = gr.Dropdown(
179
+ label="Select Task",
180
+ choices=tasks,
181
+ value='transcribe'
182
+ )
183
+ output_format_input = gr.Dropdown(
184
+ label="Select Output Format",
185
+ choices=output_formats['transcribe'],
186
+ value=output_formats['transcribe'][0]
187
+ )
188
+ language_input = gr.Dropdown(
189
+ label="Select Original Language (Optional)",
190
+ choices=languages,
191
+ value='Auto-detect'
192
+ )
193
+
194
+ task_input.change(
195
+ fn=update_output_format,
196
+ inputs=task_input,
197
+ outputs=output_format_input
198
+ )
199
+
200
+ submit_button = gr.Button("Generate")
201
+ output_file = gr.File(label="Download Output File")
202
+
203
+ submit_button.click(
204
+ fn=generate_output,
205
+ inputs=[
206
+ file_input, # Passing file_path directly
207
+ model_size_input,
208
+ task_input,
209
+ output_format_input,
210
+ language_input
211
+ ],
212
+ outputs=output_file
213
+ )
214
+
215
+ # Update the theme toggle function
216
+ def toggle_theme(current_theme):
217
+ new_theme = 'dark' if current_theme == 'light' else 'light'
218
+ js_code = f"document.body.className = '{new_theme}-mode';"
219
+ return new_theme, gr.HTML.update(value=f"<script>{js_code}</script>")
220
 
221
  theme_button = gr.Button("Toggle Theme")
222
+ theme_button.click(
223
+ fn=toggle_theme,
224
+ inputs=theme_state,
225
+ outputs=[theme_state, gr.HTML()]
226
+ )
227
 
228
  demo.launch()