Upload 2 files
Browse files- app.py +71 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
GEMINI_API_KEY=gr.Textbox(placeholder="GEMINI API KEY",type="password")
|
30 |
+
word_count=gr.Slider(minimum=50,
|
31 |
+
maximum=1000,
|
32 |
+
value=200,
|
33 |
+
step=10)
|
34 |
+
model_sel=gr.Dropdown(
|
35 |
+
choices=['gemini-2.0-flash',
|
36 |
+
'gemini-2.0-flash-lite',
|
37 |
+
'gemini-1.5-pro'],
|
38 |
+
value='gemini-2.0-flash',
|
39 |
+
label="Model Seçimi"
|
40 |
+
)
|
41 |
+
lang_sel=gr.Dropdown(
|
42 |
+
choices=['Türkçe',
|
43 |
+
'İngilizce',
|
44 |
+
'Almanca'],
|
45 |
+
value='Türkçe',
|
46 |
+
label="Dil Seçimi"
|
47 |
+
)
|
48 |
+
action_sel=gr.Dropdown(
|
49 |
+
choices=['Özetle',
|
50 |
+
'tam çeviri yap.'],
|
51 |
+
value='Özetle',
|
52 |
+
label="İşlem"
|
53 |
+
)
|
54 |
+
sum_btn=gr.Button('Özetle')
|
55 |
+
with gr.Column():
|
56 |
+
transkript_text=gr.Textbox(label='Transkripti', lines=5)
|
57 |
+
sum_text=gr.Textbox(label='Özet', lines=5)
|
58 |
+
trs_btn.click(fn=get_transcript,
|
59 |
+
inputs=video_url,
|
60 |
+
outputs=transkript_text
|
61 |
+
)
|
62 |
+
sum_btn.click(fn=fn_sum_text,
|
63 |
+
inputs=[transkript_text, word_count, model_sel, lang_sel, action_sel,GEMINI_API_KEY],
|
64 |
+
outputs=sum_text
|
65 |
+
)
|
66 |
+
|
67 |
+
demo.launch()
|
68 |
+
|
69 |
+
|
70 |
+
if __name__=='__main__':
|
71 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
youtube_transcript_api
|
2 |
+
google-genai
|