akshatsanghvi commited on
Commit
2de8440
·
1 Parent(s): f0c660a

Update app.py

Browse files

-Add Character Network

Files changed (1) hide show
  1. app.py +34 -1
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  from classifier import ThemeClassifier
 
3
 
4
  def process(theme_list, subtitles_path, save_path):
5
 
@@ -34,6 +35,23 @@ def process(theme_list, subtitles_path, save_path):
34
  return output_chart
35
 
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  def main():
39
 
@@ -52,8 +70,23 @@ def main():
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()
 
 
 
1
  import gradio as gr
2
  from classifier import ThemeClassifier
3
+ from characters import CharacterNetworkGenerator, NamedEntityRecognizer
4
 
5
  def process(theme_list, subtitles_path, save_path):
6
 
 
35
  return output_chart
36
 
37
 
38
+ def get_char_network(subtitles_path, save_path):
39
+
40
+ char_network = CharacterNetworkGenerator()
41
+ ner = NamedEntityRecognizer()
42
+
43
+ if not save_path:
44
+ save_path = "cache"
45
+
46
+ if not subtitles_path:
47
+ return char_network.defaultGraph(save_path)
48
+
49
+ ner_df = ner.get_ners(subtitles_path, save_path)
50
+ df = char_network.generate_char_network(ner_df)
51
+ html = char_network.draw_char_network(df)
52
+
53
+ return html
54
+
55
 
56
  def main():
57
 
 
70
 
71
  get_theme = gr.Button("Go")
72
  get_theme.click(process, inputs=[theme_list, subtitles_path, save_path], outputs=[plot])
73
+
74
+ # Character Network:
75
+ with gr.Row():
76
+ with gr.Column():
77
+ gr.HTML('<h2>Character Network</h2>')
78
+ with gr.Row():
79
+ with gr.Column():
80
+ network = gr.HTML()
81
+ with gr.Column():
82
+ subtitles_path = gr.Textbox(label="Subtitles or script Path")
83
+ save_path = gr.Textbox(label="Save Path")
84
+ get_network = gr.Button("Go")
85
+ get_network.click(get_char_network, inputs=[subtitles_path, save_path], outputs=[network])
86
 
87
  iface.launch(share=True)
88
 
89
  if __name__ == "__main__":
90
+ main()
91
+
92
+ # drama, vulgar, sex, sacrifice, happy, romance, love, friendship, sad, anger, betrayel, narration, funny