Jaward commited on
Commit
9de074b
·
verified ·
1 Parent(s): ff2ec2a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -32,6 +32,16 @@ import markdown
32
  import PyPDF2
33
  import io
34
  import copy
 
 
 
 
 
 
 
 
 
 
35
 
36
  def get_instructor_name(speaker):
37
  instructor_names = {
@@ -412,9 +422,9 @@ def get_gradio_file_url(local_path):
412
  # Get the base name of the file
413
  file_name = os.path.basename(local_path)
414
 
415
- # For default audio files, use the public space path
416
  if file_name in ["professor_lectura_male.mp3", "feynman.mp3", "einstein.mp3", "samantha.mp3", "socrates.mp3"]:
417
- return f"/gradio_api/file=audio_files/{file_name}"
418
 
419
  # For other files, use the relative path
420
  relative_path = os.path.relpath(local_path, os.getcwd())
@@ -2268,4 +2278,6 @@ with gr.Blocks(
2268
  demo.css += custom_css
2269
 
2270
  if __name__ == "__main__":
2271
- demo.launch(allowed_paths=[OUTPUT_DIR])
 
 
 
32
  import PyPDF2
33
  import io
34
  import copy
35
+ from pathlib import Path
36
+
37
+ # Set up static paths for file access
38
+ STATIC_DIR = Path("static")
39
+ AUDIO_DIR = STATIC_DIR / "audio"
40
+ STATIC_DIR.mkdir(exist_ok=True)
41
+ AUDIO_DIR.mkdir(exist_ok=True)
42
+
43
+ # Set static paths for Gradio
44
+ gr.set_static_paths(paths=[STATIC_DIR.absolute()])
45
 
46
  def get_instructor_name(speaker):
47
  instructor_names = {
 
422
  # Get the base name of the file
423
  file_name = os.path.basename(local_path)
424
 
425
+ # For default audio files, use the static path
426
  if file_name in ["professor_lectura_male.mp3", "feynman.mp3", "einstein.mp3", "samantha.mp3", "socrates.mp3"]:
427
+ return f"/gradio_api/file=static/audio/{file_name}"
428
 
429
  # For other files, use the relative path
430
  relative_path = os.path.relpath(local_path, os.getcwd())
 
2278
  demo.css += custom_css
2279
 
2280
  if __name__ == "__main__":
2281
+ demo.launch(
2282
+ allowed_paths=[OUTPUT_DIR, UPLOAD_DIR, str(STATIC_DIR)]
2283
+ )