wiqasali commited on
Commit
380d80f
·
verified ·
1 Parent(s): 6911cc6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -28
app.py CHANGED
@@ -1,36 +1,27 @@
1
  import streamlit as st
 
2
 
3
- # Function to convert temperatures
4
- def convert_temperature(value, from_unit, to_unit):
5
- if from_unit == 'Celsius':
6
- if to_unit == 'Fahrenheit':
7
- return (value * 9/5) + 32
8
- elif to_unit == 'Kelvin':
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("Temperature Converter")
24
 
25
- # Input temperature value
26
- temp_value = st.number_input("Enter temperature value", step=0.1)
27
 
28
- # Select units for conversion
29
- from_unit = st.selectbox("From", ["Celsius", "Fahrenheit", "Kelvin"])
30
- to_unit = st.selectbox("To", ["Celsius", "Fahrenheit", "Kelvin"])
 
 
 
 
 
 
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