Spaces:
Runtime error
Runtime error
| # --- 1. INSTALL LIBRARIES --- | |
| print("--- Installing Gradio and Transformers... ---") | |
| # We only need gradio and the AI libraries | |
| !pip install gradio transformers sentencepiece sacremoses | |
| # --- 2. IMPORT LIBRARIES AND LOAD MODEL --- | |
| import gradio as gr | |
| from transformers import pipeline | |
| print("--- Loading FAST 'aryaumesh/english-to-marathi' model... ---") | |
| # Load the fast and small model | |
| try: | |
| translator = pipeline("translation", model="aryaumesh/english-to-marathi") | |
| print("--- Model loaded successfully! ---") | |
| except Exception as e: | |
| print(f"Error loading model: {e}") | |
| translator = None | |
| # --- 3. DEFINE THE TRANSLATION FUNCTION --- | |
| # This is the function Gradio will call | |
| def translate_text(input_text): | |
| if translator is None: | |
| return "Error: Model not loaded" | |
| try: | |
| # Run the translation | |
| result = translator(input_text) | |
| return result[0]['translation_text'] | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| # --- 4. CREATE AND LAUNCH THE GRADIO APP --- | |
| print("--- Launching Gradio App... ---") | |
| # This creates the UI: a text input, a text output, and a title | |
| demo = gr.Interface( | |
| fn=translate_text, | |
| inputs=gr.Textbox(lines=5, placeholder="Enter text in English..."), | |
| outputs="text", | |
| title="English-to-Marathi AI Translator", | |
| description="A simple translator built for my project using Gradio and a Hugging Face model." | |
| ) | |
| # share=True is the magic. It creates a public URL. | |
| demo.launch(share=True) |