BurguerProXD commited on
Commit
fec2c2d
·
verified ·
1 Parent(s): 026068a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -36
app.py CHANGED
@@ -1,17 +1,16 @@
1
  import gradio as gr
2
  from huggingface_hub import hf_hub_download
3
  from llama_cpp import Llama
4
- import traceback
5
 
6
- # ⚡ Descarga y carga del modelo (solo una vez, se cachea)
7
  REPO_ID = "unsloth/Qwen2.5-Coder-0.5B-Instruct-GGUF"
8
  FILENAME = "Qwen2.5-Coder-0.5B-Instruct-Q4_K_M.gguf"
9
  model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
10
 
11
  llm = Llama(
12
  model_path=model_path,
13
- n_ctx=1024, # Contexto suficiente para respuestas
14
- n_threads=2, # Usa ambos núcleos virtuales
15
  n_batch=128,
16
  use_mmap=True,
17
  verbose=False
@@ -24,7 +23,6 @@ SYSTEM_PROMPT = (
24
  )
25
 
26
  def format_prompt(message, history):
27
- """Construye el prompt con el formato de chat de Qwen2.5."""
28
  prompt = f"<|im_start|>system\n{SYSTEM_PROMPT}<|im_end|>\n"
29
  for user_msg, bot_msg in history:
30
  prompt += f"<|im_start|>user\n{user_msg}<|im_end|>\n"
@@ -34,10 +32,8 @@ def format_prompt(message, history):
34
  return prompt
35
 
36
  def generate_response(message, history):
37
- """Genera la respuesta token a token (streaming)."""
38
  prompt = format_prompt(message, history)
39
  try:
40
- # Streaming: devolvemos cada token según se genera
41
  stream = llm(
42
  prompt,
43
  max_tokens=256,
@@ -52,47 +48,41 @@ def generate_response(message, history):
52
  partial += token
53
  yield partial
54
  except Exception as e:
55
- # En caso de error, lo mostramos en el chat
56
- yield f"❌ Error interno: {traceback.format_exc()}"
57
 
58
- # 🎨 Interfaz estilo ChatGPT / DeepSeek
59
  custom_css = """
 
60
  .gradio-container {
61
  max-width: 800px;
62
  margin: auto;
63
  font-family: 'Inter', system-ui, sans-serif;
64
  }
65
- .bubble {
66
- border-radius: 18px;
67
- padding: 12px 18px;
68
- margin: 8px 0;
69
- max-width: 80%;
70
- line-height: 1.5;
71
  }
72
- .user {
73
- background: #f0f0f0;
74
- color: #111;
75
- }
76
- .bot {
77
- background: #e3f2fd;
78
- color: #111;
79
  }
80
  footer {visibility: hidden} /* Oculta el "Flag" de Hugging Face */
81
  """
82
 
83
- iface = gr.ChatInterface(
84
- fn=generate_response,
85
- title="🤖 TixAI — Roblox Expert",
86
- description="Tu asistente definitivo para scripting, construcción y marketing en Roblox.",
87
- theme=gr.themes.Soft(),
88
- css=custom_css,
89
- examples=[
90
- "¿Cómo crear un sistema de mascotas que sigan al jugador?",
91
- "Dame un script para un obby con checkpoints.",
92
- "¿Qué gamepasses me recomiendas para monetizar un simulador?"
93
- ],
94
- cache_examples=False,
95
- )
96
 
97
  if __name__ == "__main__":
98
  iface.launch(server_name="0.0.0.0")
 
1
  import gradio as gr
2
  from huggingface_hub import hf_hub_download
3
  from llama_cpp import Llama
 
4
 
5
+ # ⚡ Configuración del modelo
6
  REPO_ID = "unsloth/Qwen2.5-Coder-0.5B-Instruct-GGUF"
7
  FILENAME = "Qwen2.5-Coder-0.5B-Instruct-Q4_K_M.gguf"
8
  model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
9
 
10
  llm = Llama(
11
  model_path=model_path,
12
+ n_ctx=1024,
13
+ n_threads=2,
14
  n_batch=128,
15
  use_mmap=True,
16
  verbose=False
 
23
  )
24
 
25
  def format_prompt(message, history):
 
26
  prompt = f"<|im_start|>system\n{SYSTEM_PROMPT}<|im_end|>\n"
27
  for user_msg, bot_msg in history:
28
  prompt += f"<|im_start|>user\n{user_msg}<|im_end|>\n"
 
32
  return prompt
33
 
34
  def generate_response(message, history):
 
35
  prompt = format_prompt(message, history)
36
  try:
 
37
  stream = llm(
38
  prompt,
39
  max_tokens=256,
 
48
  partial += token
49
  yield partial
50
  except Exception as e:
51
+ yield f"❌ Error: {e}"
 
52
 
53
+ # 🎨 Interfaz moderna estilo DeepSeek / ChatGPT
54
  custom_css = """
55
+ /* Centrar y limitar el ancho */
56
  .gradio-container {
57
  max-width: 800px;
58
  margin: auto;
59
  font-family: 'Inter', system-ui, sans-serif;
60
  }
61
+ /* Estilo de los mensajes del chat (lo maneja el componente Chatbot) */
62
+ .message.user {
63
+ background-color: #f0f0f0 !important;
64
+ color: #111 !important;
 
 
65
  }
66
+ .message.bot {
67
+ background-color: #e3f2fd !important;
68
+ color: #111 !important;
 
 
 
 
69
  }
70
  footer {visibility: hidden} /* Oculta el "Flag" de Hugging Face */
71
  """
72
 
73
+ # Construcción con Blocks (necesario para usar theme en Gradio 6)
74
+ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="TixAI — Roblox Expert") as iface:
75
+ gr.Markdown("# 🤖 TixAI — Roblox Expert")
76
+ gr.Markdown("Tu asistente definitivo para scripting, construcción y marketing en Roblox.")
77
+ chat = gr.ChatInterface(
78
+ fn=generate_response,
79
+ examples=[
80
+ "¿Cómo crear un sistema de mascotas que sigan al jugador?",
81
+ "Dame un script para un obby con checkpoints.",
82
+ "¿Qué gamepasses me recomiendas para monetizar un simulador?"
83
+ ],
84
+ cache_examples=False,
85
+ )
86
 
87
  if __name__ == "__main__":
88
  iface.launch(server_name="0.0.0.0")