temo12 commited on
Commit
08d8c5b
·
verified ·
1 Parent(s): 6b62c63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py CHANGED
@@ -1,3 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
  def process_keywords_and_video(url, excel_file):
 
1
+ # app.py
2
+
3
+ import gradio as gr
4
+ from backend import fetch_video_metadata, fetch_transcript, split_long_sentences, match_keywords_in_sentences, read_keywords
5
+ import pandas as pd
6
+
7
+ # Gradio interface function to call the backend functions
8
+ def analyze_sentiment(video_url, excel_file_path):
9
+ # Fetch video metadata
10
+ metadata, metadata_error = fetch_video_metadata(video_url)
11
+ if metadata_error:
12
+ return f"Error: {metadata_error}"
13
+
14
+ # Fetch transcript
15
+ transcript, transcript_error = fetch_transcript(video_url)
16
+ if transcript_error:
17
+ return f"Error: {transcript_error}"
18
+
19
+ # Process sentences from transcript
20
+ sentences = split_long_sentences(transcript)
21
+
22
+ # Read keywords from uploaded Excel file
23
+ keywords, attributes = read_keywords(excel_file_path)
24
+
25
+ # Match keywords in sentences
26
+ matched_keywords = match_keywords_in_sentences(sentences, keywords)
27
+
28
+ # Prepare the report for Gradio display
29
+ report = {
30
+ "Metadata": metadata,
31
+ "Matched Keywords": matched_keywords,
32
+ "Sentences": sentences
33
+ }
34
+
35
+ return report
36
+
37
+ # Gradio interface setup
38
+ interface = gr.Interface(
39
+ fn=analyze_sentiment,
40
+ inputs=[
41
+ gr.inputs.Textbox(label="YouTube Video URL"),
42
+ gr.inputs.File(label="Upload Keywords Excel File") # User uploads keywords file
43
+ ],
44
+ outputs=[
45
+ gr.outputs.JSON(label="Metadata and Sentiment Analysis Results"),
46
+ gr.outputs.Textbox(label="Sentences from Transcript") # Display sentences detected in transcript
47
+ ]
48
+ )
49
+
50
+ # Launch Gradio interface
51
+ interface.launch()
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
  import gradio as gr
62
 
63
  def process_keywords_and_video(url, excel_file):