Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from huggingface_hub import hf_hub_download | |
| from llama_cpp import Llama | |
| # ⚡ Configuración del modelo | |
| REPO_ID = "unsloth/Qwen2.5-Coder-0.5B-Instruct-GGUF" | |
| FILENAME = "Qwen2.5-Coder-0.5B-Instruct-Q4_K_M.gguf" | |
| model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME) | |
| llm = Llama( | |
| model_path=model_path, | |
| n_ctx=1024, | |
| n_threads=2, | |
| n_batch=128, | |
| use_mmap=True, | |
| verbose=False | |
| ) | |
| SYSTEM_PROMPT = ( | |
| "Eres TixAI, un asistente de IA superinteligente especializado en Roblox, scripting Luau, " | |
| "construcción de juegos y marketing. Responde SIEMPRE en español, de forma concisa y útil. " | |
| "Incluye ejemplos de código cuando sea relevante." | |
| ) | |
| def format_prompt(message, history): | |
| prompt = f"<|im_start|>system\n{SYSTEM_PROMPT}<|im_end|>\n" | |
| for user_msg, bot_msg in history: | |
| prompt += f"<|im_start|>user\n{user_msg}<|im_end|>\n" | |
| prompt += f"<|im_start|>assistant\n{bot_msg}<|im_end|>\n" | |
| prompt += f"<|im_start|>user\n{message}<|im_end|>\n" | |
| prompt += "<|im_start|>assistant\n" | |
| return prompt | |
| def generate_response(message, history): | |
| prompt = format_prompt(message, history) | |
| try: | |
| stream = llm( | |
| prompt, | |
| max_tokens=256, | |
| temperature=0.6, | |
| top_p=0.9, | |
| stop=["<|im_end|>", "<|im_start|>"], | |
| stream=True, | |
| ) | |
| partial = "" | |
| for chunk in stream: | |
| token = chunk["choices"][0]["text"] | |
| partial += token | |
| yield partial | |
| except Exception as e: | |
| yield f"❌ Error: {e}" | |
| # 🎨 Interfaz moderna estilo DeepSeek / ChatGPT | |
| custom_css = """ | |
| /* Centrar y limitar el ancho */ | |
| .gradio-container { | |
| max-width: 800px; | |
| margin: auto; | |
| font-family: 'Inter', system-ui, sans-serif; | |
| } | |
| /* Estilo de los mensajes del chat (lo maneja el componente Chatbot) */ | |
| .message.user { | |
| background-color: #f0f0f0 !important; | |
| color: #111 !important; | |
| } | |
| .message.bot { | |
| background-color: #e3f2fd !important; | |
| color: #111 !important; | |
| } | |
| footer {visibility: hidden} /* Oculta el "Flag" de Hugging Face */ | |
| """ | |
| # Construcción con Blocks (necesario para usar theme en Gradio 6) | |
| with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="TixAI — Roblox Expert") as iface: | |
| gr.Markdown("# 🤖 TixAI — Roblox Expert") | |
| gr.Markdown("Tu asistente definitivo para scripting, construcción y marketing en Roblox.") | |
| chat = gr.ChatInterface( | |
| fn=generate_response, | |
| examples=[ | |
| "¿Cómo crear un sistema de mascotas que sigan al jugador?", | |
| "Dame un script para un obby con checkpoints.", | |
| "¿Qué gamepasses me recomiendas para monetizar un simulador?" | |
| ], | |
| cache_examples=False, | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch(server_name="0.0.0.0") |