Kuzey-Arda commited on
Commit
28711d3
·
verified ·
1 Parent(s): 0299bc5

Upload 2 files

Browse files
Files changed (2) hide show
  1. main.py +71 -0
  2. requirements.txt +2 -0
main.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
+ def get_transcript(video_url):
8
+ video_id=video_url.split("v=")[1].split("&")[0]
9
+ transcript=YouTubeTranscriptApi.get_transcript(video_id,languages=['en','tr'])
10
+ raw_text=" ".join([entry['text'] for entry in transcript])
11
+ return raw_text
12
+
13
+
14
+ def fn_sum_text(video_url, transkript_text, word_count, model_sel, lang_sel, action_sel,GEMINI_API_KEY, slider_enable):
15
+ if transkript_text == None:
16
+ get_transcript(video_url=video_url)
17
+ client=genai.Client(api_key=GEMINI_API_KEY)
18
+ if slider_enable==True:
19
+ prompt=f"{transkript_text} metni {word_count} sayıda kelimeyle {lang_sel} dilinde {action_sel}"
20
+ else:
21
+ prompt=f"{transkript_text} metni {lang_sel} dilinde {action_sel}"
22
+
23
+ response=client.models.generate_content(
24
+ model=model_sel,
25
+ contents=[prompt]
26
+ )
27
+ return (response.text)
28
+
29
+
30
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
31
+ with gr.Row():
32
+ with gr.Column():
33
+ video_url=gr.Textbox(placeholder="Youtube Video URL Giriniz.", label="Youtube Video URL")
34
+ trs_btn=gr.Button('Transkripti Al')
35
+ GEMINI_API_KEY=gr.Textbox(placeholder="GEMINI API KEY",type="password", label="GEMINI API KEY Giriniz")
36
+ word_count=gr.Slider(minimum=50,
37
+ maximum=1000,
38
+ value=200,
39
+ step=10)
40
+ slider_enable = gr.Checkbox(value=True,label="Slider'i kullan")
41
+ model_sel = gr.Dropdown(["gemini-2.0-flash", "gemini-2.0-flash-lite", "gemini-1.5-flash", "gemini-1.5-flash-8b", "gemini-1.5-pro"], value="gemini-2.0-flash", label="Model", info="Model seçiniz")
42
+ lang_sel=gr.Dropdown(
43
+ choices=['Türkçe',
44
+ 'İngilizce',
45
+ 'Almanca'],
46
+ value='Türkçe',
47
+ label="Dil Seçimi"
48
+ )
49
+ action_sel=gr.Dropdown(
50
+ choices=['Özetle',
51
+ 'tam çeviri yap.'],
52
+ value='Özetle',
53
+ label="İşlem"
54
+ )
55
+ sum_btn=gr.Button('Özetle')
56
+ with gr.Column():
57
+ transkript_text=gr.Textbox(label='Transkripti', lines=5)
58
+ sum_text=gr.Textbox(label='Özet', lines=5)
59
+ trs_btn.click(fn=get_transcript,
60
+ inputs=video_url,
61
+ outputs=transkript_text
62
+ )
63
+ sum_btn.click(fn=fn_sum_text,
64
+ inputs=[transkript_text, word_count, model_sel, lang_sel, action_sel, GEMINI_API_KEY, slider_enable],
65
+ outputs=sum_text
66
+ )
67
+
68
+
69
+
70
+ if __name__ == "__main__":
71
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ google-genai
2
+ youtube_transcript_api