yunuseduran commited on
Commit
ca6a1a9
·
verified ·
1 Parent(s): 54ffab8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -71
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
- 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()
 
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()