wiqasali commited on
Commit
3c87765
·
verified ·
1 Parent(s): 853bff9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -22
app.py CHANGED
@@ -1,29 +1,36 @@
1
  import streamlit as st
2
- from transformers import pipeline
3
 
4
- # Set up the translation pipeline using Hugging Face's MarianMT model
5
- @st.cache_resource
6
- def load_model():
7
- translator = pipeline("translation_en_to_ur", model="Helsinki-NLP/opus-mt-en-ur")
8
- return translator
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- # Load the translation model
11
- translator = load_model()
12
 
13
- def translate(text):
14
- return translator(text)[0]['translation_text']
15
 
16
- # Streamlit interface
17
- st.title("English to Urdu Translation")
 
18
 
19
- # Input text
20
- input_text = st.text_area("Enter English text to translate", "")
 
 
21
 
22
- # Button to trigger translation
23
- if st.button("Translate"):
24
- if input_text.strip():
25
- translated_text = translate(input_text)
26
- st.subheader("Translated Urdu:")
27
- st.write(translated_text)
28
- else:
29
- st.warning("Please enter some text to translate.")
 
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