marks commited on
Commit
eb7a05f
·
1 Parent(s): b95827e

Added static

Browse files
Files changed (1) hide show
  1. app.py +22 -2
app.py CHANGED
@@ -1,4 +1,6 @@
1
  from fastapi import FastAPI
 
 
2
  import gradio as gr
3
  from scraper import scrape_url
4
  from podcast_generator import PodcastGenerator
@@ -7,6 +9,18 @@ import uvicorn
7
 
8
  app = FastAPI()
9
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  def generate_podcast(url):
11
  content = scrape_url(url)
12
  podcast_generator = PodcastGenerator()
@@ -14,7 +28,7 @@ def generate_podcast(url):
14
  audio_file = text_to_speech(podcast_text)
15
  return audio_file
16
 
17
- # Create Gradio interface
18
  demo = gr.Interface(
19
  fn=generate_podcast,
20
  inputs=gr.Textbox(
@@ -26,12 +40,18 @@ demo = gr.Interface(
26
  description="Enter a URL to generate a podcast episode based on its content.",
27
  theme="huggingface",
28
  allow_flagging="never",
 
 
29
  )
30
 
31
- # Mount Gradio interface to FastAPI
32
  app = gr.mount_gradio_app(app, demo, path="/")
33
 
34
  if __name__ == "__main__":
 
 
 
 
35
  uvicorn.run(
36
  "app:app",
37
  host="0.0.0.0",
 
1
  from fastapi import FastAPI
2
+ from fastapi.staticfiles import StaticFiles
3
+ from fastapi.middleware.cors import CORSMiddleware
4
  import gradio as gr
5
  from scraper import scrape_url
6
  from podcast_generator import PodcastGenerator
 
9
 
10
  app = FastAPI()
11
 
12
+ # Add CORS middleware
13
+ app.add_middleware(
14
+ CORSMiddleware,
15
+ allow_origins=["*"],
16
+ allow_credentials=True,
17
+ allow_methods=["*"],
18
+ allow_headers=["*"],
19
+ )
20
+
21
+ # Mount static files
22
+ app.mount("/static", StaticFiles(directory="static"), name="static")
23
+
24
  def generate_podcast(url):
25
  content = scrape_url(url)
26
  podcast_generator = PodcastGenerator()
 
28
  audio_file = text_to_speech(podcast_text)
29
  return audio_file
30
 
31
+ # Create Gradio interface with custom configuration
32
  demo = gr.Interface(
33
  fn=generate_podcast,
34
  inputs=gr.Textbox(
 
40
  description="Enter a URL to generate a podcast episode based on its content.",
41
  theme="huggingface",
42
  allow_flagging="never",
43
+ css="static/custom.css", # Optional: for any custom CSS
44
+ analytics_enabled=False,
45
  )
46
 
47
+ # Mount Gradio app with a specific base path
48
  app = gr.mount_gradio_app(app, demo, path="/")
49
 
50
  if __name__ == "__main__":
51
+ import os
52
+ # Create static directory if it doesn't exist
53
+ os.makedirs("static", exist_ok=True)
54
+
55
  uvicorn.run(
56
  "app:app",
57
  host="0.0.0.0",