Spaces:
Running
Running
Rivalcoder
commited on
Commit
·
caa912d
1
Parent(s):
dcdeeb3
[Edit Of Add]
Browse files
app.py
CHANGED
@@ -1,11 +1,6 @@
|
|
1 |
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 |
-
import uvicorn
|
6 |
-
|
7 |
-
# Initialize FastAPI app
|
8 |
-
app = FastAPI()
|
9 |
|
10 |
# Initialize the YouTubeTranscriptApi with proxy configuration
|
11 |
ytt_api = YouTubeTranscriptApi(
|
@@ -25,22 +20,14 @@ def fetch_transcript(video_id: str):
|
|
25 |
except Exception as e:
|
26 |
return f"Error fetching transcript: {str(e)}"
|
27 |
|
28 |
-
# Gradio Interface
|
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 |
-
#
|
37 |
-
|
38 |
-
def read_root():
|
39 |
-
return {"message": "Welcome to the YouTube Transcript API!"}
|
40 |
-
|
41 |
-
# Mount Gradio interface to FastAPI app
|
42 |
-
iface.launch(server_name="0.0.0.0", server_port=8000, ssr_mode=False)
|
43 |
-
|
44 |
-
# Launch the FastAPI app using Uvicorn
|
45 |
-
if __name__ == "__main__":
|
46 |
-
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
1 |
import gradio as gr
|
|
|
2 |
from youtube_transcript_api import YouTubeTranscriptApi
|
3 |
from youtube_transcript_api.proxies import WebshareProxyConfig
|
|
|
|
|
|
|
|
|
4 |
|
5 |
# Initialize the YouTubeTranscriptApi with proxy configuration
|
6 |
ytt_api = YouTubeTranscriptApi(
|
|
|
20 |
except Exception as e:
|
21 |
return f"Error fetching transcript: {str(e)}"
|
22 |
|
23 |
+
# Gradio Interface for API (no UI)
|
24 |
iface = gr.Interface(
|
25 |
fn=fetch_transcript,
|
26 |
inputs=gr.Textbox(label="Enter YouTube Video ID"),
|
27 |
outputs=gr.Textbox(label="Transcript"),
|
28 |
+
live=False,
|
29 |
+
api=True # This flag turns the interface into an API
|
30 |
)
|
31 |
|
32 |
+
# Launch the Gradio app in API mode
|
33 |
+
iface.launch(share=True) # share=True allows external access to the API
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|