import streamlit as st from langchain_google_genai import ChatGoogleGenerativeAI st.title("Language Translator") def translate_text(text, target_language, api_key): llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=api_key) prompt = ( f"Translate the following text into {target_language} and provide the phonetic transcription (how it can be written in English):\n\n" f"{text}\n\n" f"Translation:" ) response = llm.invoke(prompt) return response.content with st.form("translation_form"): text = st.text_area("Enter the text to translate") target_language = st.text_input("Enter the target language: ") submitted = st.form_submit_button("Translate") if submitted and text and target_language: api_key = st.secrets["GOOGLE_API_KEY"] translation = translate_text(text, target_language, api_key) st.info(translation) elif submitted and not text: st.error("Please enter text to translate.") elif submitted and not target_language: st.error("Please enter the target language.")