Spaces:
Build error
Build error
| import gradio as gr | |
| from google import genai | |
| import os | |
| # Get API key from environment variable (set this in Hugging Face Secrets) | |
| API_KEY = os.getenv("GEMINI_API_KEY") | |
| if not API_KEY: | |
| raise EnvironmentError("Missing GEMINI_API_KEY. Set it in Hugging Face Spaces → Secrets.") | |
| # Initialize the Gemini client | |
| client = genai.Client(api_key=API_KEY) | |
| # Load Gemini model | |
| model = client.models.get("models/gemini-2.0-flash") | |
| # Translation function | |
| def sober_up(drunk_text): | |
| if not drunk_text.strip(): | |
| return "Please enter a message." | |
| prompt = f"Translate this drunk message into a sober, coherent version: '{drunk_text}'" | |
| try: | |
| response = model.generate_content(contents=prompt) | |
| return response.text | |
| except Exception as e: | |
| return f"Error: {e}" | |
| # Gradio Interface | |
| demo = gr.Interface( | |
| fn=sober_up, | |
| inputs=gr.Textbox(lines=4, placeholder="Paste your chaotic, drunk text here..."), | |
| outputs="text", | |
| title="🍺 SoberUp Translator", | |
| description="AI-powered translator for decoding drunk messages into sober, coherent statements using Gemini Flash." | |
| ) | |
| # Launch app | |
| if __name__ == "__main__": | |
| demo.launch() | |