suricodes's picture
Update app.py
65749c3 verified
import streamlit as st
import sys
import xmlrpc
from xmlrpc import client
import pandas as pd
# Title for the page and nice icon
st.set_page_config(page_title="Hindi-Sindhi MT Model", page_icon="🤖", layout='wide')
st.markdown("""
<style> .block-container {
padding-top: 1rem;
padding-bottom: 0rem;
padding-left: 5rem;
padding-right: 5rem;
}
</style>
""", unsafe_allow_html=True)
# Header
st.header("Machine Translation System - Hindi to Sindhi", divider='rainbow')
st.write("**-Developed at Speech and Language Processing Lab, Center for Artificial Intelligence, Banasthali Vidyapith. Sponsored by SERB, GoI, :flag-in:.**")
# ===========================================================================
def translate(source):
proxy = xmlrpc.client.ServerProxy("http://localhost:8083/RPC2")
print(source)
text_translate = proxy.translate({"text":source}) ["text"]
print(text_translate)
lst = text_translate.split("\n")
src = source.split("\n")
final_output = ''
for i in lst:
final_output += i + '\n'
return final_output
# ===========================================================================
c1, c2 = st.columns(2)
element = c2.empty()
user_input = c1.text_area("Source Text", max_chars=200000, height=500)
output = element.text_area("Target Text", max_chars=200000, height=500)
translation = translate(user_input)
submitted = st.button("Translate")
if submitted:
new_output = element.text_area('New Target Text', value=translation, height=500, max_chars=200000)
# +++++++++++++++++++++++ BOSS KA ORIGINAL CODE ++++++++++++++++++++++++++++++++
# def translate(source):
# proxy = xmlrpc.client.ServerProxy("http://172.16.40.175:8083/RPC2")
# print(source)
# text_translate = proxy.translate({"text":source}) ["text"]
# print(text_translate)
# lst = text_translate.split("\n")
# src = source.split("\n")
# df = pd.DataFrame()
# df["Source"] = src
# df["Translations"] = lst
# return df
# with st.form("my_form"):
# # Textarea to type the source text.
# user_input = st.text_area("Source Text", max_chars=200000)
# # Translate with CTranslate2 model
# translation = translate(user_input)
# # Create a button
# submitted = st.form_submit_button("Translate")
# # If the button pressed, print the translation
# # Here, we use "st.info", but you can try "st.write", "st.code", or "st.success".
# if submitted:
# st.write("Translation")
# st.dataframe(translation)
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++