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()