Spaces:
Running
Running
File size: 1,596 Bytes
ae7d660 2e7c2af d2271c1 0927160 d2271c1 ae7d660 ddb299c d2271c1 ae7d660 f3f2a1e ae7d660 d2271c1 f3f2a1e d2271c1 f3f2a1e ae7d660 f3f2a1e d2271c1 f3f2a1e d2271c1 f3f2a1e d2271c1 f3f2a1e d2271c1 ae7d660 7be0cb3 |
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 38 39 40 41 42 43 44 45 46 |
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()
|