Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from google import genai
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Read API key from Hugging Face secret
|
| 6 |
+
API_KEY = os.getenv("GEMINI_API_KEY")
|
| 7 |
+
if not API_KEY:
|
| 8 |
+
raise ValueError("Missing GEMINI_API_KEY. Make sure it is set in Hugging Face secrets.")
|
| 9 |
+
|
| 10 |
+
# Configure Gemini client
|
| 11 |
+
genai.configure(api_key=API_KEY)
|
| 12 |
+
model = genai.GenerativeModel(model_name="gemini-2.0-flash")
|
| 13 |
+
|
| 14 |
+
def sober_up(drunk_text):
|
| 15 |
+
if not drunk_text.strip():
|
| 16 |
+
return "Please enter a message."
|
| 17 |
+
prompt = f"Translate this drunk message into a sober, coherent version: '{drunk_text}'"
|
| 18 |
+
try:
|
| 19 |
+
response = model.generate_content(prompt)
|
| 20 |
+
return response.text
|
| 21 |
+
except Exception as e:
|
| 22 |
+
return f"Error: {e}"
|
| 23 |
+
|
| 24 |
+
demo = gr.Interface(
|
| 25 |
+
fn=sober_up,
|
| 26 |
+
inputs=gr.Textbox(lines=4, placeholder="Paste your chaotic, drunk text here..."),
|
| 27 |
+
outputs="text",
|
| 28 |
+
title="🍺 SoberUp Translator",
|
| 29 |
+
description="AI-powered translator for decoding drunk messages into coherent text."
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
demo.launch()
|