ammaan commited on
Commit
40b8269
·
verified ·
1 Parent(s): 6a5cebd

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +11 -6
main.py CHANGED
@@ -9,17 +9,17 @@ from fastapi.responses import FileResponse
9
 
10
  app = FastAPI()
11
 
12
- text_summary = pipeline("summarization", model="Falconsai/text_summarization", max_length=12000)
13
 
14
 
15
- def extract_video_id(url: str) -> Union[str, None]:
16
  regex = r"(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})"
17
  match = re.search(regex, url)
18
  if match:
19
  return match.group(1)
20
  return None
21
 
22
- def get_youtube_transcript(video_url: str) -> Union[str, None]:
23
  video_id = extract_video_id(video_url)
24
  if not video_id:
25
  return "Video ID could not be extracted."
@@ -31,14 +31,14 @@ def get_youtube_transcript(video_url: str) -> Union[str, None]:
31
  except Exception as e:
32
  return f"An error occurred: {e}"
33
 
34
- def summarize_text(text: str) -> str:
35
  summarized_text = text_summary(text)
36
  return summarized_text[0]['summary_text']
37
 
38
  # Get the input from the frontend
39
  @app.get("/getdata")
40
- def get_data(input: str = Query(..., title="YouTube Video URL")) -> dict:
41
-
42
  transcript = get_youtube_transcript(input)
43
  if transcript:
44
  summary = summarize_text(transcript)
@@ -54,3 +54,8 @@ app.mount('/', StaticFiles(directory="static", html=True), name="static")
54
  @app.get('/')
55
  def index() -> FileResponse:
56
  return FileResponse('/app/static/index.html', media_type="text/html")
 
 
 
 
 
 
9
 
10
  app = FastAPI()
11
 
12
+ text_summary = pipeline("summarization", model="Falconsai/text_summarization", max_length=1200)
13
 
14
 
15
+ def extract_video_id(url):
16
  regex = r"(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})"
17
  match = re.search(regex, url)
18
  if match:
19
  return match.group(1)
20
  return None
21
 
22
+ def get_youtube_transcript(video_url):
23
  video_id = extract_video_id(video_url)
24
  if not video_id:
25
  return "Video ID could not be extracted."
 
31
  except Exception as e:
32
  return f"An error occurred: {e}"
33
 
34
+ def summarize_text(text):
35
  summarized_text = text_summary(text)
36
  return summarized_text[0]['summary_text']
37
 
38
  # Get the input from the frontend
39
  @app.get("/getdata")
40
+ def get_data(input):
41
+ print(input)
42
  transcript = get_youtube_transcript(input)
43
  if transcript:
44
  summary = summarize_text(transcript)
 
54
  @app.get('/')
55
  def index() -> FileResponse:
56
  return FileResponse('/app/static/index.html', media_type="text/html")
57
+
58
+
59
+ if __name__ == "__main__":
60
+ import uvicorn
61
+ uvicorn.run(app, host="127.0.0.1", port=5050)