Spaces:
Build error
Build error
File size: 1,124 Bytes
8c53dc1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import transformers
import streamlit as st
# Load the English-to-Urdu translation model
model_name = "Helsinki-NLP/opus-mt-en-ur"
tokenizer = transformers.AutoTokenizer.from_pretrained(model_name)
model = transformers.AutoModelForSeq2SeqLM.from_pretrained(model_name)
# Create a dictionary of physics terms
physics_terms = {
"force": "قوت",
"mass": "جرم",
"acceleration": "تسارع",
# Add more terms here
}
# Streamlit app
def main():
st.title("Physics Terms Dictionary")
term = st.text_input("Enter a physics term:")
if term:
if term in physics_terms:
urdu_term = physics_terms[term]
st.write(f"Urdu Term: {urdu_term}")
# Translate the explanation using the model
inputs = tokenizer(term, return_tensors="pt")
outputs = model.generate(**inputs)
translated_explanation = tokenizer.decode(outputs[0], skip_special_tokens=True)
st.write(f"Explanation: {translated_explanation}")
else:
st.warning("Term not found in the dictionary.")
if __name__ == "__main__":
main() |