dmahata commited on
Commit
07eed3f
1 Parent(s): 5e1d6fc

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +110 -0
app.py ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import pandas as pd
4
+ import os
5
+ from run_eval import run_generate
6
+
7
+ st.write("# GupShup")
8
+ st.write("## Summarizing Open-Domain Code-Switched Conversations")
9
+ task_type = st.sidebar.selectbox(
10
+ "Task type", ["Hinglish to English", "English to English"]
11
+ )
12
+ model_name = st.sidebar.selectbox(
13
+ "Model", ["Pegasus", "mBart", "Bart", "GPT", "T5", "T5_MTL"]
14
+ )
15
+
16
+ src_form = st.sidebar.form(key="src_form")
17
+ src_ip = src_form.text_input(label="Please enter path to conversastion/source file")
18
+ tar_ip = src_form.text_input(
19
+ label="Please enter path to summary/target file. [optional]"
20
+ )
21
+ src_submit_button = src_form.form_submit_button(label="Submit")
22
+ st.sidebar.markdown("<h1 style='text-align: center;'>OR</h1>", unsafe_allow_html=True)
23
+
24
+
25
+ conv_form = st.sidebar.form(key="conv_form")
26
+ conv_ip = conv_form.text_input(label="Please enter the conversastion")
27
+ conv_submit_button = conv_form.form_submit_button(label="Submit")
28
+ st.write("### Task Type:", task_type)
29
+ st.write("### Model:", model_name)
30
+ x = "fg"
31
+
32
+ src_file = None
33
+ tar_file = None
34
+ gen_file = "generated_summary.txt"
35
+ score_file = None
36
+
37
+
38
+ if conv_submit_button:
39
+ if conv_ip == "":
40
+ st.write("Pls enter non empty conversastion")
41
+
42
+ else:
43
+ st.write("### Summarizing below Conversastion")
44
+ st.write(conv_ip)
45
+ src_file = "conversastion.txt"
46
+ src_fp = open(src_file, "w")
47
+ src_fp.write(conv_ip)
48
+ src_fp.close()
49
+ # st.write( "### Summary")
50
+
51
+
52
+ if src_submit_button:
53
+ if src_ip == "":
54
+ st.write("### Please enter path to conversastion file")
55
+ elif os.path.isfile(src_ip) == False:
56
+ st.write("### Path to conversastion file is invalid")
57
+
58
+ else:
59
+ src_file = src_ip
60
+ st.write("summarizing conversastion stored in ", src_file)
61
+ if tar_ip != "" and os.path.isfile(tar_ip):
62
+ tar_file = tar_ip
63
+
64
+ score_file = "scores.txt"
65
+ else:
66
+ st.wrie(
67
+ "Target file is not provided or invalid, score will not be calculated"
68
+ )
69
+
70
+ # src and tar file chaeck
71
+ st.write(" src and tar")
72
+ st.write(src_ip)
73
+ st.write(tar_ip)
74
+
75
+ tt = "h2e"
76
+ if task_type == "English to English":
77
+ tt = "e2e"
78
+ elif task_type == "Hinglish to English":
79
+ tt = "h2e"
80
+ model_name_path = "midas/gupshup_" + str(tt) + "_" + str(model_name).lower()
81
+
82
+ if src_file == None or os.path.isfile(src_file) == False:
83
+ st.write("### source file is empty or invalid")
84
+ else:
85
+
86
+ result = run_generate(
87
+ verbose=True,
88
+ model_name_path=model_name_path,
89
+ src_txt=src_file,
90
+ tar_txt=tar_file,
91
+ gen_path=gen_file,
92
+ scor_path=score_file,
93
+ batch_size=8,
94
+ )
95
+
96
+ if conv_submit_button:
97
+ st.write("summary:")
98
+ fp = open(gen_file, "r")
99
+ summary = fp.readlines()
100
+ fp.close()
101
+ st.write(summary)
102
+
103
+ if src_submit_button and result!=None:
104
+ if tar_file != None:
105
+ st.write("scores: ", result)
106
+
107
+ st.write("summary is stored in ", gen_file)
108
+
109
+
110
+ # st.write(x)