Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,27 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
|
3 |
-
#
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
return value + 273.15
|
10 |
-
elif from_unit == 'Fahrenheit':
|
11 |
-
if to_unit == 'Celsius':
|
12 |
-
return (value - 32) * 5/9
|
13 |
-
elif to_unit == 'Kelvin':
|
14 |
-
return ((value - 32) * 5/9) + 273.15
|
15 |
-
elif from_unit == 'Kelvin':
|
16 |
-
if to_unit == 'Celsius':
|
17 |
-
return value - 273.15
|
18 |
-
elif to_unit == 'Fahrenheit':
|
19 |
-
return ((value - 273.15) * 9/5) + 32
|
20 |
-
return value
|
21 |
|
22 |
# Streamlit app layout
|
23 |
-
st.title("
|
24 |
|
25 |
-
# Input
|
26 |
-
|
27 |
|
28 |
-
#
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
# Convert button
|
33 |
-
if st.button("Convert"):
|
34 |
-
converted_value = convert_temperature(temp_value, from_unit, to_unit)
|
35 |
-
st.write(f"{temp_value} {from_unit} is equal to {converted_value:.2f} {to_unit}")
|
36 |
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
# Initialize the translation pipeline from Hugging Face
|
5 |
+
@st.cache_resource
|
6 |
+
def load_translation_model():
|
7 |
+
return pipeline("translation_en_to_ur", model="Helsinki-NLP/opus-mt-en-ur")
|
8 |
+
|
9 |
+
translator = load_translation_model()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
# Streamlit app layout
|
12 |
+
st.title("English to Urdu Translator")
|
13 |
|
14 |
+
# Input text in English
|
15 |
+
english_text = st.text_area("Enter English text", placeholder="Type something in English...", height=150)
|
16 |
|
17 |
+
# Translate button
|
18 |
+
if st.button("Translate to Urdu"):
|
19 |
+
if english_text.strip() != "":
|
20 |
+
translation = translator(english_text)
|
21 |
+
urdu_text = translation[0]['translation_text']
|
22 |
+
st.write("### Translated Text in Urdu:")
|
23 |
+
st.write(urdu_text)
|
24 |
+
else:
|
25 |
+
st.warning("Please enter some text to translate!")
|
26 |
|
|
|
|
|
|
|
|
|
27 |
|