|
import streamlit as st |
|
import numpy as np |
|
import pandas as pd |
|
import os |
|
from run_eval import run_generate |
|
|
|
default_value = "summarize: Nick: Opinions required! Gas ya induction hob? Ben: Bahut time se ek induction hob use kar raha huu, mai convinced nahi huu.. Ruth: induction- bahut sleek hai jadi garam ho jaata hai! Ben: but voh constant temperature maintain nahi karta! Kya saare induction aise hee hai yaa maine purana waala liya tha? Ruth: they pulse agar proper pans nahi use karte hum Ben: proper se tumhara kya matlab? Kya tumhara matlab better aur bhari? Ruth: yeah, simply suitable Ben: and mujhe lagta hai mujhe usse chalana seekhna padega.. Ruth: yeah, yeh gas se alag hai Christian: gas, bina kisi saval ke- aur koi cheez tumhe control nahi deti! Nick: Mai usme interested huu jisme mujhe mere hissab se consistent heat mile Mary: with induction tumhe usse shuru aur band karna padega to regulate temperature.. Kate: induction- yes, gas- no kyuki paani ubalne mein sadiyaan lag jaati hai! Tim: tum jaante ho naa tum ek electric kettle use kar sakte ho? Kate: haha! Yeh funny nahi hai! Kate: yeh saaf karne mein bhi aasan hai. Harry: mai induction lunga kyuki voh khaana banane ke baad bhi usse garam rakhta hai Tom: Induction! 100% Susan: humara induction bahut ganda tha I think it s common! Emma: induction ke liye ek aur vote! Ruth: All chefs seem to say gas! Tom: mai gas se zyaada induction hobs bechta huu! yeh popular hota jaa raha hai aur mai dekh ssakta huu kyu! Emma: humne humara waala John Lewis outlet se liya so it was ex display aur isliye bahut sasta tha! Nick: tumhari raaye ke liye thanks! Great talk! Mujhe lagta hai mai Induction lunga." |
|
|
|
st.write("# GupShup") |
|
st.write("## Summarizing Open-Domain Code-Switched Conversations - [https://github.com/midas-research/gupshup](https://github.com/midas-research/gupshup)") |
|
task_type = st.sidebar.selectbox( |
|
"Task type", ["Hinglish to English", "English to English"] |
|
) |
|
model_name = st.sidebar.selectbox( |
|
"Model", ["mBart", "Pegasus", "Bart", "T5"] |
|
) |
|
|
|
src_form = st.sidebar.form(key="src_form") |
|
src_ip = src_form.text_input(label="Please enter path to conversastion/source file") |
|
tar_ip = src_form.text_input( |
|
label="Please enter path to summary/target file. [optional]" |
|
) |
|
src_submit_button = src_form.form_submit_button(label="Submit") |
|
st.sidebar.markdown("<h1 style='text-align: center;'>OR</h1>", unsafe_allow_html=True) |
|
|
|
|
|
conv_form = st.sidebar.form(key="conv_form") |
|
conv_ip = conv_form.text_input(label="Please enter the conversastion", value=default_value) |
|
conv_submit_button = conv_form.form_submit_button(label="Submit") |
|
st.write("### Task Type:", task_type) |
|
st.write("### Model:", model_name) |
|
x = "fg" |
|
|
|
src_file = None |
|
tar_file = None |
|
gen_file = "generated_summary.txt" |
|
score_file = None |
|
|
|
|
|
if conv_submit_button: |
|
if conv_ip == "": |
|
st.write("Pls enter non empty conversastion") |
|
|
|
else: |
|
st.write("### Summarizing below Conversastion") |
|
st.write(conv_ip) |
|
src_file = "conversastion.txt" |
|
src_fp = open(src_file, "w") |
|
src_fp.write(conv_ip) |
|
src_fp.close() |
|
|
|
|
|
|
|
if src_submit_button: |
|
if src_ip == "": |
|
st.write("### Please enter path to conversastion file") |
|
elif os.path.isfile(src_ip) == False: |
|
st.write("### Path to conversastion file is invalid") |
|
|
|
else: |
|
src_file = src_ip |
|
st.write("summarizing conversastion stored in ", src_file) |
|
if tar_ip != "" and os.path.isfile(tar_ip): |
|
tar_file = tar_ip |
|
|
|
score_file = "scores.txt" |
|
else: |
|
st.write( |
|
"Target file is not provided or invalid, score will not be calculated" |
|
) |
|
|
|
|
|
st.write(" src and tar") |
|
st.write(src_ip) |
|
st.write(tar_ip) |
|
|
|
tt = "h2e" |
|
if task_type == "English to English": |
|
tt = "e2e" |
|
elif task_type == "Hinglish to English": |
|
tt = "h2e" |
|
model_name_path = "midas/gupshup_" + str(tt) + "_" + str(model_name).lower() |
|
|
|
if src_file == None or os.path.isfile(src_file) == False: |
|
st.write("##### Hit the submit button on the left with the default conversation or enter your own conversation if you don't have the source files.") |
|
else: |
|
|
|
result = run_generate( |
|
verbose=True, |
|
model_name_path=model_name_path, |
|
src_txt=src_file, |
|
tar_txt=tar_file, |
|
gen_path=gen_file, |
|
scor_path=score_file, |
|
batch_size=8, |
|
) |
|
|
|
if conv_submit_button: |
|
st.write("summary:") |
|
fp = open(gen_file, "r") |
|
summary = fp.readlines() |
|
fp.close() |
|
st.write(summary) |
|
|
|
if src_submit_button and result!=None: |
|
if tar_file != None: |
|
st.write("scores: ", result) |
|
|
|
st.write("summary is stored in ", gen_file) |
|
|
|
|
|
|
|
|