Spaces:
Runtime error
Runtime error
Primer_commit
Browse files
app.py
CHANGED
|
@@ -7,17 +7,17 @@ import gradio as gr
|
|
| 7 |
import torch
|
| 8 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 9 |
|
| 10 |
-
# Detectar si hay GPU disponible
|
| 11 |
device = 0 if torch.cuda.is_available() else -1
|
| 12 |
|
| 13 |
-
# Cargar el modelo y el tokenizador
|
| 14 |
model_name = "microsoft/Phi-4-mini-instruct"
|
| 15 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 16 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 17 |
if device == 0:
|
| 18 |
model.to("cuda")
|
| 19 |
|
| 20 |
-
# Crear un pipeline de generaci贸n de texto utilizando
|
| 21 |
generator = pipeline("text-generation", model=model, tokenizer=tokenizer, device=device)
|
| 22 |
|
| 23 |
# Funci贸n para obtener las reservaciones de hotel filtradas por t铆tulo
|
|
@@ -129,7 +129,7 @@ iface = gr.Interface(
|
|
| 129 |
fn=process_instruction,
|
| 130 |
inputs=gr.Textbox(lines=5, placeholder="Escribe tu instrucci贸n aqu铆...", label="Instrucci贸n"),
|
| 131 |
outputs="text",
|
| 132 |
-
title="Demo de Function Calling con Phi-4-mini-instruct (
|
| 133 |
)
|
| 134 |
|
| 135 |
if __name__ == "__main__":
|
|
|
|
| 7 |
import torch
|
| 8 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 9 |
|
| 10 |
+
# Detectar si hay GPU disponible, de lo contrario usar CPU (-1)
|
| 11 |
device = 0 if torch.cuda.is_available() else -1
|
| 12 |
|
| 13 |
+
# Cargar el modelo y el tokenizador (se usar谩 CPU si no hay GPU)
|
| 14 |
model_name = "microsoft/Phi-4-mini-instruct"
|
| 15 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 16 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 17 |
if device == 0:
|
| 18 |
model.to("cuda")
|
| 19 |
|
| 20 |
+
# Crear un pipeline de generaci贸n de texto utilizando el dispositivo adecuado
|
| 21 |
generator = pipeline("text-generation", model=model, tokenizer=tokenizer, device=device)
|
| 22 |
|
| 23 |
# Funci贸n para obtener las reservaciones de hotel filtradas por t铆tulo
|
|
|
|
| 129 |
fn=process_instruction,
|
| 130 |
inputs=gr.Textbox(lines=5, placeholder="Escribe tu instrucci贸n aqu铆...", label="Instrucci贸n"),
|
| 131 |
outputs="text",
|
| 132 |
+
title="Demo de Function Calling con Phi-4-mini-instruct (CPU)"
|
| 133 |
)
|
| 134 |
|
| 135 |
if __name__ == "__main__":
|