Spaces:
Paused
Paused
Update app.py
Browse files
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 |
-
|
|
|
|
| 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 |
-
|
|
|
|
| 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-
|
| 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)
|