Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
|
| 4 |
-
import requests
|
| 5 |
from typing import List, Dict, Union, Tuple
|
| 6 |
-
import json
|
| 7 |
from data import (
|
| 8 |
PROFESSIONS,
|
| 9 |
LACE_THONG_STYLES,
|
|
@@ -42,11 +40,19 @@ VOYEUR_SPECIALIST_CONFIG = {
|
|
| 42 |
],
|
| 43 |
}
|
| 44 |
|
| 45 |
-
#
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
# ============================================
|
| 52 |
# PROMPT DEL SISTEMA
|
|
@@ -91,14 +97,25 @@ def build_prompt(user_text: str) -> str:
|
|
| 91 |
return SYSTEM_PROMPT_BASE + "\n\nUSER:\n" + user_text
|
| 92 |
|
| 93 |
def call_model(prompt: str) -> str:
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
def infer(user_text: str) -> str:
|
| 104 |
prompt = build_prompt(user_text)
|
|
@@ -134,20 +151,20 @@ def get_system_config_ui() -> str:
|
|
| 134 |
"""
|
| 135 |
|
| 136 |
# ============================================
|
| 137 |
-
# CSS MODERNO
|
| 138 |
# ============================================
|
| 139 |
|
| 140 |
CUSTOM_CSS = """
|
| 141 |
<style>
|
| 142 |
-
body { background-color: #
|
| 143 |
-
.gradio-container { background: #
|
| 144 |
h1 { color: #ff7043; }
|
| 145 |
button { background-color: #ff7043 !important; color:white !important; }
|
| 146 |
</style>
|
| 147 |
"""
|
| 148 |
|
| 149 |
# ============================================
|
| 150 |
-
# INTERFAZ GRADIO
|
| 151 |
# ============================================
|
| 152 |
|
| 153 |
with gr.Blocks(title="Voyeur Prompt Generator") as demo:
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
|
|
|
|
| 4 |
from typing import List, Dict, Union, Tuple
|
|
|
|
| 5 |
from data import (
|
| 6 |
PROFESSIONS,
|
| 7 |
LACE_THONG_STYLES,
|
|
|
|
| 40 |
],
|
| 41 |
}
|
| 42 |
|
| 43 |
+
# ============================================
|
| 44 |
+
# CLIENTE DEL MODELO (OPCIONAL SI FALLA)
|
| 45 |
+
# ============================================
|
| 46 |
+
|
| 47 |
+
try:
|
| 48 |
+
from sambanova import SambaNova
|
| 49 |
+
|
| 50 |
+
client = SambaNova(
|
| 51 |
+
api_key=os.getenv("SAMBANOVA_API_KEY"),
|
| 52 |
+
base_url=os.getenv("SAMBANOVA_BASE_URL"),
|
| 53 |
+
)
|
| 54 |
+
except Exception:
|
| 55 |
+
client = None
|
| 56 |
|
| 57 |
# ============================================
|
| 58 |
# PROMPT DEL SISTEMA
|
|
|
|
| 97 |
return SYSTEM_PROMPT_BASE + "\n\nUSER:\n" + user_text
|
| 98 |
|
| 99 |
def call_model(prompt: str) -> str:
|
| 100 |
+
if client is None:
|
| 101 |
+
return "鈿狅笍 Error de configuraci贸n del modelo (SambaNova). Revisa tu SAMBANOVA_API_KEY y SAMBANOVA_BASE_URL."
|
| 102 |
+
try:
|
| 103 |
+
response = client.chat.completions.create(
|
| 104 |
+
model=MODEL_NAME,
|
| 105 |
+
messages=[
|
| 106 |
+
{"role": "system", "content": SYSTEM_PROMPT_BASE},
|
| 107 |
+
{"role": "user", "content": prompt},
|
| 108 |
+
],
|
| 109 |
+
)
|
| 110 |
+
# Ajusta seg煤n el formato real del SDK
|
| 111 |
+
choice = response.choices[0]
|
| 112 |
+
# algunas SDKs exponen .message.content, otras solo .text
|
| 113 |
+
content = getattr(getattr(choice, "message", None), "content", None)
|
| 114 |
+
if not content:
|
| 115 |
+
content = getattr(choice, "text", "")
|
| 116 |
+
return content or "Sin contenido en la respuesta del modelo."
|
| 117 |
+
except Exception as e:
|
| 118 |
+
return f"鈿狅笍 Error llamando al modelo: {e}"
|
| 119 |
|
| 120 |
def infer(user_text: str) -> str:
|
| 121 |
prompt = build_prompt(user_text)
|
|
|
|
| 151 |
"""
|
| 152 |
|
| 153 |
# ============================================
|
| 154 |
+
# CSS MODERNO
|
| 155 |
# ============================================
|
| 156 |
|
| 157 |
CUSTOM_CSS = """
|
| 158 |
<style>
|
| 159 |
+
body { background-color: #111111; }
|
| 160 |
+
.gradio-container { background: #181a1f; border-radius: 12px; padding: 20px; }
|
| 161 |
h1 { color: #ff7043; }
|
| 162 |
button { background-color: #ff7043 !important; color:white !important; }
|
| 163 |
</style>
|
| 164 |
"""
|
| 165 |
|
| 166 |
# ============================================
|
| 167 |
+
# INTERFAZ GRADIO
|
| 168 |
# ============================================
|
| 169 |
|
| 170 |
with gr.Blocks(title="Voyeur Prompt Generator") as demo:
|