Hwilner commited on
Commit
a257a11
·
verified ·
1 Parent(s): 2538977

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -20
app.py CHANGED
@@ -1,18 +1,18 @@
1
  import re
2
  from youtube_transcript_api import YouTubeTranscriptApi
3
  from youtube_transcript_api.formatters import TextFormatter
4
- import torch
5
- import gradio as gr
6
- from transformers import pipeline
7
 
8
- text_summary = pipeline("summarization", model="dicta-il/dictalm2.0", torch_dtype=torch.bfloat16)
 
9
 
10
-
11
-
12
-
13
- def summary (input):
14
- output = text_summary(input)
15
- return output[0]['summary_text']
 
16
 
17
  def extract_video_id(url):
18
  # Regex to extract the video ID from various YouTube URL formats
@@ -22,7 +22,6 @@ def extract_video_id(url):
22
  return match.group(1)
23
  return None
24
 
25
-
26
  def get_youtube_transcript(video_url):
27
  video_id = extract_video_id(video_url)
28
  if not video_id:
@@ -35,23 +34,19 @@ def get_youtube_transcript(video_url):
35
  # Format the transcript into plain text
36
  formatter = TextFormatter()
37
  text_transcript = formatter.format_transcript(transcript)
 
 
38
  summary_text = summary(text_transcript)
39
 
40
  return summary_text
41
  except Exception as e:
42
  return f"An error occurred: {e}"
43
 
44
-
45
- # Example URL (Replace this with the actual URL when using the script)
46
- # video_url = "https://youtu.be/5PibknhIsTc"
47
- # print(get_youtube_transcript(video_url))
48
-
49
  gr.close_all()
50
 
51
- # demo = gr.Interface(fn=summary, inputs="text",outputs="text")
52
  demo = gr.Interface(fn=get_youtube_transcript,
53
- inputs=[gr.Textbox(label="Input YouTube Url to summarize",lines=1)],
54
- outputs=[gr.Textbox(label="Summarized text",lines=4)],
55
- title=" YouTube Script Summarizer-Hebrew",
56
  description="THIS APPLICATION WILL BE USED TO SUMMARIZE THE YOUTUBE VIDEO SCRIPT.")
57
  demo.launch()
 
1
  import re
2
  from youtube_transcript_api import YouTubeTranscriptApi
3
  from youtube_transcript_api.formatters import TextFormatter
4
+ from gradio_client import Client
 
 
5
 
6
+ # Initialize the Gradio client with your app's name
7
+ client = Client("Hwilner/hebrew_summerizer")
8
 
9
+ def summary(input_text):
10
+ # Use the API endpoint to get the summary
11
+ result = client.predict(
12
+ input_text,
13
+ api_name="/predict"
14
+ )
15
+ return result
16
 
17
  def extract_video_id(url):
18
  # Regex to extract the video ID from various YouTube URL formats
 
22
  return match.group(1)
23
  return None
24
 
 
25
  def get_youtube_transcript(video_url):
26
  video_id = extract_video_id(video_url)
27
  if not video_id:
 
34
  # Format the transcript into plain text
35
  formatter = TextFormatter()
36
  text_transcript = formatter.format_transcript(transcript)
37
+
38
+ # Get the summary from the API
39
  summary_text = summary(text_transcript)
40
 
41
  return summary_text
42
  except Exception as e:
43
  return f"An error occurred: {e}"
44
 
 
 
 
 
 
45
  gr.close_all()
46
 
 
47
  demo = gr.Interface(fn=get_youtube_transcript,
48
+ inputs=[gr.Textbox(label="Input YouTube Url to summarize", lines=1)],
49
+ outputs=[gr.Textbox(label="Summarized text", lines=4)],
50
+ title="YouTube Script Summarizer - Hebrew",
51
  description="THIS APPLICATION WILL BE USED TO SUMMARIZE THE YOUTUBE VIDEO SCRIPT.")
52
  demo.launch()