Cristobal299 commited on
Commit
a75f4f7
Β·
verified Β·
1 Parent(s): 5bf8975

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -14
app.py CHANGED
@@ -4,11 +4,12 @@ import torch
4
  import tempfile
5
  import asyncio
6
  import gradio as gr
7
- from transformers import AutoTokenizer, AutoModelForCausalLM
8
  import edge_tts
9
  import pdfplumber
10
 
11
- MODEL_ID = "Qwen/Qwen2.5-Coder-7B-Instruct"
 
12
  API_KEY = os.environ.get("BRAIN_API_KEY", "")
13
  TTS_VOZ = "es-ES-AlvaroNeural"
14
 
@@ -19,14 +20,24 @@ SYSTEM_DEFAULT = (
19
 
20
  print("Cargando tokenizer...")
21
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
 
 
 
 
 
 
 
 
 
22
  print("Cargando modelo...")
23
  model = AutoModelForCausalLM.from_pretrained(
24
  MODEL_ID,
25
- torch_dtype=torch.bfloat16,
 
26
  low_cpu_mem_usage=True,
27
  trust_remote_code=True,
28
  )
29
- print("Modelo listo βœ…")
30
 
31
 
32
  # ── TTS ───────────────────────────────────────────────────────────────────────
@@ -136,7 +147,7 @@ VOCES = {
136
  }
137
 
138
  with gr.Blocks(title="🧠 FΓ©nix Brain", theme=gr.themes.Base()) as demo:
139
- gr.Markdown("# 🧠 Fénix Brain\nQwen2.5-Coder-7B · Documentos · Voz")
140
 
141
  with gr.Tab("πŸ’¬ Chat"):
142
  with gr.Row():
@@ -174,14 +185,5 @@ result = client.predict(
174
  max_tokens=1024,
175
  api_name="/generar"
176
  )
177
- ```
178
- """)
179
- api_prompt = gr.Textbox(label="Prompt")
180
- api_system = gr.Textbox(label="System", value=SYSTEM_DEFAULT)
181
- api_key_box = gr.Textbox(label="API Key", type="password")
182
- api_out = gr.Textbox(label="Respuesta", lines=10)
183
- gr.Button("Probar API").click(
184
- generar, [api_prompt, api_system, api_key_box], api_out, api_name="generar"
185
- )
186
 
187
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
4
  import tempfile
5
  import asyncio
6
  import gradio as gr
7
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
8
  import edge_tts
9
  import pdfplumber
10
 
11
+ # ── ConfiguraciΓ³n Principal ───────────────────────────────────────────────────
12
+ MODEL_ID = "Qwen/Qwen2.5-Coder-32B-Instruct"
13
  API_KEY = os.environ.get("BRAIN_API_KEY", "")
14
  TTS_VOZ = "es-ES-AlvaroNeural"
15
 
 
20
 
21
  print("Cargando tokenizer...")
22
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
23
+
24
+ print("Configurando motor de cuantizaciΓ³n (4-bits)...")
25
+ quantization_config = BitsAndBytesConfig(
26
+ load_in_4bit=True,
27
+ bnb_4bit_compute_dtype=torch.bfloat16,
28
+ bnb_4bit_use_double_quant=True,
29
+ bnb_4bit_quant_type="nf4"
30
+ )
31
+
32
  print("Cargando modelo...")
33
  model = AutoModelForCausalLM.from_pretrained(
34
  MODEL_ID,
35
+ quantization_config=quantization_config,
36
+ device_map="auto",
37
  low_cpu_mem_usage=True,
38
  trust_remote_code=True,
39
  )
40
+ print("Modelo 32B listo βœ…")
41
 
42
 
43
  # ── TTS ───────────────────────────────────────────────────────────────────────
 
147
  }
148
 
149
  with gr.Blocks(title="🧠 FΓ©nix Brain", theme=gr.themes.Base()) as demo:
150
+ gr.Markdown("# 🧠 Fénix Brain\nQwen2.5-Coder-32B-Instruct (4-bit) · Documentos · Voz")
151
 
152
  with gr.Tab("πŸ’¬ Chat"):
153
  with gr.Row():
 
185
  max_tokens=1024,
186
  api_name="/generar"
187
  )
 
 
 
 
 
 
 
 
 
188
 
189
  demo.launch(server_name="0.0.0.0", server_port=7860)