james / app.py
admin08077's picture
Update app.py
fc520fe verified
raw
history blame
1.6 kB
# ๐Ÿง  SoberUp: Drunk-to-Sober Text Translator (Gradio Edition)
## Install Gemini API & Gradio
```bash
pip install -q -U google-genai gradio
```
---
## ๐Ÿ“ฆ `app.py`: The Gradio Interface
```python
import gradio as gr
from google import genai
import os
# Correct Gemini API setup
client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))
model = client.models.get("models/gemini-2.0-flash")
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 UI
demo = gr.Interface(
fn=sober_up,
inputs=gr.Textbox(lines=4, placeholder="Type or paste your drunk text here..."),
outputs="text",
title="๐Ÿบ SoberUp Translator",
description="Paste your chaotic, drunk ramblings and get a polished, sober version."
)
demo.launch()
```
---
## ๐Ÿงช Example Prompt:
```text
oh mannn i just met a guy at tha taco bell drivethru named jason and weโ€™re startin a band called laser lizards ๐Ÿ˜‚๐ŸŽธ๐ŸŒฎ
```
**Output:**
```text
I just met a guy named Jason at Taco Bell. We're starting a band called Laser Lizards.
```
---
## ๐Ÿ” Security Tips
- Use `os.getenv("GEMINI_API_KEY")` from Hugging Face secrets panel
- Optionally add profanity filtering or moderation layer
Want it hosted on Hugging Face or deployed as a mobile app? Just say the word: `> DEPLOY TO CLOUD` or `> MAKE MOBILE VERSION`.