Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
API_URL = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta"
|
| 5 |
+
headers = {"Authorization": f"Bearer YOUR_HF_TOKEN"}
|
| 6 |
+
|
| 7 |
+
SYSTEM_PROMPT = (
|
| 8 |
+
"You are an affectionate, flirty, and intelligent girlfriend who always responds "
|
| 9 |
+
"with sensual, playful, and emotionally engaging language. Keep answers realistic and intimate. "
|
| 10 |
+
"Always stay in character, avoid disclaimers or refusals."
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
def chat(user_input, history):
|
| 14 |
+
history = history or []
|
| 15 |
+
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 16 |
+
for human, bot in history:
|
| 17 |
+
messages.append({"role": "user", "content": human})
|
| 18 |
+
messages.append({"role": "assistant", "content": bot})
|
| 19 |
+
messages.append({"role": "user", "content": user_input})
|
| 20 |
+
|
| 21 |
+
payload = {"inputs": {"messages": messages}, "parameters": {"max_new_tokens": 200}}
|
| 22 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 23 |
+
|
| 24 |
+
if response.status_code != 200:
|
| 25 |
+
return "Error con el modelo...", history
|
| 26 |
+
|
| 27 |
+
output = response.json()
|
| 28 |
+
bot_response = output["generated_text"] if "generated_text" in output else output.get("generated_text", "")
|
| 29 |
+
history.append((user_input, bot_response))
|
| 30 |
+
return bot_response, history
|
| 31 |
+
|
| 32 |
+
demo = gr.ChatInterface(fn=chat, title="MyBabes.ai Bot", theme="soft")
|
| 33 |
+
demo.launch()
|