rudrashah commited on
Commit
cc92c69
β€’
1 Parent(s): d39b121

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ def model(sentence):
5
+ pipe = pipeline("translation", model="rudrashah/RLM-hinglish-translator")
6
+ output = pipe(sentence)
7
+ output = output.replace("<bos>", "")
8
+ return output[len(sentence):].strip()
9
+
10
+ def translate_hinglish_to_english(text):
11
+ translated_text = model(text)
12
+ st.session_state['translated_text'] = translated_text
13
+ return translated_text
14
+
15
+ model("aapka name kya hai?")
16
+
17
+ st.set_page_config(page_title="RLM-Translator", page_icon="πŸ•", layout="wide", initial_sidebar_state="collapsed")
18
+
19
+ st.title("RLM-Translator")
20
+ st.write("A simple Hinglish to English translator from Hugging Face by [Rudra Shah](https://huggingface.co/rudrashah/RLM-hinglish-translator).")
21
+
22
+ col1, col2 = st.columns(2)
23
+
24
+ with col1:
25
+ hinglish_text = st.text_area("Hinglish", height=300)
26
+
27
+ with col2:
28
+ if "translated_text" in st.session_state:
29
+ st.text_area("English", value=st.session_state["translated_text"], height=300, key="")
30
+ else:
31
+ st.text_area("English", height=300, key="")
32
+
33
+ if st.button("Translate", use_container_width=True, type="primary"):
34
+ if hinglish_text != "":
35
+ translated_text = translate_hinglish_to_english(hinglish_text)
36
+ st.session_state["translated_text"] = translated_text
37
+ st.rerun()
38
+ else:
39
+ st.error("Please enter some hinglish text to translate.")