Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,71 +1,70 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from google import genai
|
3 |
-
from youtube_transcript_api import YouTubeTranscriptApi
|
4 |
-
from youtube_transcript_api._errors import TranscriptsDisabled, NoTranscriptFound, VideoUnavailable
|
5 |
-
|
6 |
-
|
7 |
-
#https://www.youtube.com/watch?v=bhR274lZNLo
|
8 |
-
def get_transcript(video_url):
|
9 |
-
video_id=video_url.split("v=")[1].split("&")[0]
|
10 |
-
#return video_id
|
11 |
-
transcript=YouTubeTranscriptApi.get_transcript(video_id,languages=['en','tr'])
|
12 |
-
raw_text=" ".join([entry['text'] for entry in transcript])
|
13 |
-
return raw_text
|
14 |
-
#print (get_transcript("https://www.youtube.com/watch?v=bhR274lZNLo"))
|
15 |
-
def fn_sum_text(transkript_text, word_count, model_sel, lang_sel, action_sel,GEMINI_API_KEY):
|
16 |
-
client=genai.Client(api_key=GEMINI_API_KEY)
|
17 |
-
prompt=f"{transkript_text} metni {word_count} sayıda kelimeyle {lang_sel} dilinde {action_sel}"
|
18 |
-
response=client.models.generate_content(
|
19 |
-
model=model_sel,
|
20 |
-
contents=[prompt]
|
21 |
-
)
|
22 |
-
return (response.text)
|
23 |
-
#video_url='https://www.youtube.com/watch?v=bhR274lZNLo'
|
24 |
-
with gr.Blocks() as demo:
|
25 |
-
with gr.Row():
|
26 |
-
with gr.Column():
|
27 |
-
video_url=gr.Textbox(placeholder="Youtube Video URL")
|
28 |
-
trs_btn=gr.Button('Transkripti Al')
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
'gemini-
|
37 |
-
'gemini-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
'
|
44 |
-
'
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
'
|
51 |
-
|
52 |
-
|
53 |
-
)
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
demo.launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from google import genai
|
3 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
4 |
+
from youtube_transcript_api._errors import TranscriptsDisabled, NoTranscriptFound, VideoUnavailable
|
5 |
+
|
6 |
+
|
7 |
+
#https://www.youtube.com/watch?v=bhR274lZNLo
|
8 |
+
def get_transcript(video_url):
|
9 |
+
video_id=video_url.split("v=")[1].split("&")[0]
|
10 |
+
#return video_id
|
11 |
+
transcript=YouTubeTranscriptApi.get_transcript(video_id,languages=['en','tr'])
|
12 |
+
raw_text=" ".join([entry['text'] for entry in transcript])
|
13 |
+
return raw_text
|
14 |
+
#print (get_transcript("https://www.youtube.com/watch?v=bhR274lZNLo"))
|
15 |
+
def fn_sum_text(transkript_text, word_count, model_sel, lang_sel, action_sel,GEMINI_API_KEY):
|
16 |
+
client=genai.Client(api_key=GEMINI_API_KEY)
|
17 |
+
prompt=f"{transkript_text} metni {word_count} sayıda kelimeyle {lang_sel} dilinde {action_sel}"
|
18 |
+
response=client.models.generate_content(
|
19 |
+
model=model_sel,
|
20 |
+
contents=[prompt]
|
21 |
+
)
|
22 |
+
return (response.text)
|
23 |
+
#video_url='https://www.youtube.com/watch?v=bhR274lZNLo'
|
24 |
+
with gr.Blocks() as demo:
|
25 |
+
with gr.Row():
|
26 |
+
with gr.Column():
|
27 |
+
video_url=gr.Textbox(placeholder="Youtube Video URL")
|
28 |
+
trs_btn=gr.Button('Transkripti Al')
|
29 |
+
word_count=gr.Slider(minimum=50,
|
30 |
+
maximum=1000,
|
31 |
+
value=200,
|
32 |
+
step=10)
|
33 |
+
model_sel=gr.Dropdown(
|
34 |
+
choices=['gemini-2.0-flash',
|
35 |
+
'gemini-2.0-flash-lite',
|
36 |
+
'gemini-1.5-pro'],
|
37 |
+
value='gemini-2.0-flash',
|
38 |
+
label="Model Seçimi"
|
39 |
+
)
|
40 |
+
lang_sel=gr.Dropdown(
|
41 |
+
choices=['Türkçe',
|
42 |
+
'İngilizce',
|
43 |
+
'Almanca'],
|
44 |
+
value='Türkçe',
|
45 |
+
label="Dil Seçimi"
|
46 |
+
)
|
47 |
+
action_sel=gr.Dropdown(
|
48 |
+
choices=['Özetle',
|
49 |
+
'tam çeviri yap.'],
|
50 |
+
value='Özetle',
|
51 |
+
label="İşlem"
|
52 |
+
)
|
53 |
+
sum_btn=gr.Button('Özetle')
|
54 |
+
with gr.Column():
|
55 |
+
transkript_text=gr.Textbox(label='Transkripti', lines=5)
|
56 |
+
sum_text=gr.Textbox(label='Özet', lines=5)
|
57 |
+
trs_btn.click(fn=get_transcript,
|
58 |
+
inputs=video_url,
|
59 |
+
outputs=transkript_text
|
60 |
+
)
|
61 |
+
sum_btn.click(fn=fn_sum_text,
|
62 |
+
inputs=[transkript_text, word_count, model_sel, lang_sel, action_sel,GEMINI_API_KEY],
|
63 |
+
outputs=sum_text
|
64 |
+
)
|
65 |
+
|
66 |
+
demo.launch()
|
67 |
+
|
68 |
+
|
69 |
+
if __name__=='__main__':
|
70 |
+
demo.launch()
|
|