Spaces:
Running
Running
Updating Space
Browse files- app.py +36 -55
- requirements.txt +3 -1
app.py
CHANGED
|
@@ -1,64 +1,45 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
"""
|
| 5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 6 |
-
"""
|
| 7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
)
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
"""
|
| 44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 45 |
-
"""
|
| 46 |
-
demo = gr.ChatInterface(
|
| 47 |
-
respond,
|
| 48 |
-
additional_inputs=[
|
| 49 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 50 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 51 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 52 |
-
gr.Slider(
|
| 53 |
-
minimum=0.1,
|
| 54 |
-
maximum=1.0,
|
| 55 |
-
value=0.95,
|
| 56 |
-
step=0.05,
|
| 57 |
-
label="Top-p (nucleus sampling)",
|
| 58 |
-
),
|
| 59 |
-
],
|
| 60 |
)
|
| 61 |
|
| 62 |
-
|
| 63 |
if __name__ == "__main__":
|
| 64 |
demo.launch()
|
|
|
|
| 1 |
+
import re
|
| 2 |
import gradio as gr
|
| 3 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
| 4 |
from huggingface_hub import InferenceClient
|
| 5 |
|
|
|
|
|
|
|
|
|
|
| 6 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 7 |
|
| 8 |
+
def get_video_id(youtube_url: str) -> str:
|
| 9 |
+
"""
|
| 10 |
+
Extract the video ID from a given YouTube URL.
|
| 11 |
+
"""
|
| 12 |
+
# Typical patterns:
|
| 13 |
+
# https://www.youtube.com/watch?v=VIDEO_ID
|
| 14 |
+
# https://youtu.be/VIDEO_ID
|
| 15 |
+
# https://www.youtube.com/shorts/VIDEO_ID
|
| 16 |
+
pattern = r"(?:v=|/shorts/|\.be/)([^&\n?#]+)"
|
| 17 |
+
match = re.search(pattern, youtube_url)
|
| 18 |
+
if not match:
|
| 19 |
+
raise ValueError("Could not extract video ID from the provided URL.")
|
| 20 |
+
return match.group(1)
|
| 21 |
+
|
| 22 |
+
def fetch_transcript(youtube_url: str) -> str:
|
| 23 |
+
"""
|
| 24 |
+
Given a YouTube URL, fetch the transcript and return it as a single string.
|
| 25 |
+
"""
|
| 26 |
+
try:
|
| 27 |
+
video_id = get_video_id(youtube_url)
|
| 28 |
+
# Fetch transcript
|
| 29 |
+
transcript_data = YouTubeTranscriptApi.get_transcript(video_id)
|
| 30 |
+
# Combine the transcript lines
|
| 31 |
+
transcript = " ".join([entry["text"] for entry in transcript_data])
|
| 32 |
+
return transcript
|
| 33 |
+
except Exception as e:
|
| 34 |
+
return f"Error fetching transcript: {str(e)}"
|
| 35 |
+
|
| 36 |
+
demo = gr.Interface(
|
| 37 |
+
fn=fetch_transcript,
|
| 38 |
+
inputs=gr.Textbox(label="YouTube URL"),
|
| 39 |
+
outputs="text",
|
| 40 |
+
title="YouTube Transcript Fetcher",
|
| 41 |
+
description="Enter a YouTube link to retrieve its transcript."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
)
|
| 43 |
|
|
|
|
| 44 |
if __name__ == "__main__":
|
| 45 |
demo.launch()
|
requirements.txt
CHANGED
|
@@ -1 +1,3 @@
|
|
| 1 |
-
huggingface_hub==0.25.2
|
|
|
|
|
|
|
|
|
| 1 |
+
huggingface_hub==0.25.2
|
| 2 |
+
gradio==5.12.0
|
| 3 |
+
youtube-transcript-api==0.6.3
|