mdasad3617's picture
Update app.py
f3f2a1e verified
raw
history blame
1.6 kB
import streamlit as st
from transformers import pipeline
import logging
# Setup logging
def setup_logging():
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler()
]
)
def main():
setup_logging()
logging.info("Starting the Streamlit app.")
# Initialize the translation pipeline for English to Hinglish
translator = pipeline("translation", model="surajp/eng_to_hinglish") # Replace with your desired model
# Streamlit UI
st.title("English to Hinglish Translator")
st.write("Type or paste your English text below, and get the Hinglish translation.")
text = st.text_area("Enter your English text here:", placeholder="Type here...")
if st.button("Translate"):
try:
if text:
logging.info("Translating English text to Hinglish.")
result = translator(text, max_length=200)
translation = result[0]['translation_text'] if result else "No translation available."
st.text_area("Hinglish Translation:", translation, height=200)
logging.info("Translation completed successfully.")
else:
st.warning("Please enter text to translate.")
except Exception as e:
logging.error(f"Error during translation: {e}")
st.error("An error occurred during translation. Please check the logs for more details.")
logging.info("Closing the Streamlit app.")
if __name__ == "__main__":
main()