akshatsanghvi commited on
Commit
dcd9bd1
·
1 Parent(s): 60d53e2

Create app.py

Browse files

- Create process function to process subtitles for classification.
- Create Layout for Zero Shot classification and corresponding barplot.

Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from classifier import ThemeClassifier
3
+
4
+ def process(theme_list, subtitles_path, save_path):
5
+
6
+ if not save_path:
7
+ save_path = "cache"
8
+
9
+ if not subtitles_path:
10
+ subtitles_path = "data/subs"
11
+
12
+ theme_list = theme_list.split(",")
13
+ themes = [theme.lower().strip() for theme in theme_list]
14
+ clf = ThemeClassifier(themes)
15
+
16
+
17
+ output_df = clf.get_themes(subtitles_path,save_path)
18
+ output_df = output_df[themes]
19
+
20
+ output_df = output_df[themes].sum().reset_index()
21
+ output_df.columns = ['Theme','Score']
22
+
23
+ output_chart = gr.BarPlot(
24
+ output_df,
25
+ x="Theme",
26
+ y="Score",
27
+ title="Series Themes",
28
+ tooltip=["Theme","Score"],
29
+ vertical=False,
30
+ width=500,
31
+ height=260
32
+ )
33
+
34
+ return output_chart
35
+
36
+
37
+
38
+ def main():
39
+
40
+ # Theme Classification (Zero Shot Classifier):
41
+ with gr.Blocks() as iface:
42
+ with gr.Row():
43
+ with gr.Column():
44
+ gr.HTML('<h1>How I Met Your Mother</h1><h2>Theme Classification (Zero Shot Classifier)</h2>')
45
+ with gr.Row():
46
+ with gr.Column():
47
+ plot = gr.BarPlot()
48
+ with gr.Column():
49
+ theme_list = gr.Textbox(label="Themes")
50
+ subtitles_path = gr.Textbox(label="Subtitles or script Path")
51
+ save_path = gr.Textbox(label="Save Path")
52
+
53
+ get_theme = gr.Button("Go")
54
+ get_theme.click(process, inputs=[theme_list, subtitles_path, save_path], outputs=[plot])
55
+
56
+ iface.launch(share=True)
57
+
58
+ if __name__ == "__main__":
59
+ main()