Rivalcoder commited on
Commit
7539cb9
·
1 Parent(s): aa1df32
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  from fastapi import FastAPI
3
  from youtube_transcript_api import YouTubeTranscriptApi
4
  from youtube_transcript_api.proxies import WebshareProxyConfig
 
5
 
6
  # Initialize FastAPI app
7
  app = FastAPI()
@@ -24,13 +25,12 @@ def fetch_transcript(video_id: str):
24
  except Exception as e:
25
  return f"Error fetching transcript: {str(e)}"
26
 
27
- # Gradio Interface for API (no UI)
28
  iface = gr.Interface(
29
  fn=fetch_transcript,
30
  inputs=gr.Textbox(label="Enter YouTube Video ID"),
31
  outputs=gr.Textbox(label="Transcript"),
32
- live=False,
33
- api=True # This flag turns the interface into an API
34
  )
35
 
36
  # FastAPI route to serve Gradio app
@@ -38,10 +38,9 @@ iface = gr.Interface(
38
  def read_root():
39
  return {"message": "Welcome to the YouTube Transcript API!"}
40
 
41
- # Embed the Gradio interface as a FastAPI app
42
- iface.mount(app)
43
 
44
- # Launch the FastAPI app
45
  if __name__ == "__main__":
46
- import uvicorn
47
  uvicorn.run(app, host="0.0.0.0", port=8000)
 
2
  from fastapi import FastAPI
3
  from youtube_transcript_api import YouTubeTranscriptApi
4
  from youtube_transcript_api.proxies import WebshareProxyConfig
5
+ import uvicorn
6
 
7
  # Initialize FastAPI app
8
  app = FastAPI()
 
25
  except Exception as e:
26
  return f"Error fetching transcript: {str(e)}"
27
 
28
+ # Gradio Interface (no need for api=True, directly mount Gradio to FastAPI)
29
  iface = gr.Interface(
30
  fn=fetch_transcript,
31
  inputs=gr.Textbox(label="Enter YouTube Video ID"),
32
  outputs=gr.Textbox(label="Transcript"),
33
+ live=False
 
34
  )
35
 
36
  # FastAPI route to serve Gradio app
 
38
  def read_root():
39
  return {"message": "Welcome to the YouTube Transcript API!"}
40
 
41
+ # Mount Gradio interface to FastAPI app
42
+ iface.launch(share=True, server_name="0.0.0.0", server_port=8000)
43
 
44
+ # Launch the FastAPI app using Uvicorn
45
  if __name__ == "__main__":
 
46
  uvicorn.run(app, host="0.0.0.0", port=8000)