Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
-
import torch
|
4 |
-
from transformers import
|
5 |
-
from huggingface_hub import login
|
6 |
|
7 |
# Iniciar sesi贸n en Hugging Face usando el secreto
|
8 |
huggingface_token = os.getenv('reparbot2') # Aseg煤rate de que el nombre coincida
|
@@ -10,18 +9,23 @@ if huggingface_token is None:
|
|
10 |
raise ValueError("El token de Hugging Face no est谩 configurado en las variables de entorno.")
|
11 |
login(huggingface_token)
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
17 |
|
18 |
# Funci贸n para responder a la consulta
|
19 |
def respond_to_query(user_input):
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
return
|
25 |
|
26 |
# Crear la interfaz de Gradio
|
27 |
gr.Interface(fn=respond_to_query, inputs="text", outputs="text").launch()
|
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
+
import torch
|
4 |
+
from transformers import pipeline
|
|
|
5 |
|
6 |
# Iniciar sesi贸n en Hugging Face usando el secreto
|
7 |
huggingface_token = os.getenv('reparbot2') # Aseg煤rate de que el nombre coincida
|
|
|
9 |
raise ValueError("El token de Hugging Face no est谩 configurado en las variables de entorno.")
|
10 |
login(huggingface_token)
|
11 |
|
12 |
+
# Configurar el modelo
|
13 |
+
model_id = "meta-llama/Llama-3.3-70B-Instruct"
|
14 |
+
pipeline_model = pipeline(
|
15 |
+
"text-generation",
|
16 |
+
model=model_id,
|
17 |
+
model_kwargs={"torch_dtype": torch.bfloat16},
|
18 |
+
device_map="auto",
|
19 |
+
)
|
20 |
|
21 |
# Funci贸n para responder a la consulta
|
22 |
def respond_to_query(user_input):
|
23 |
+
messages = [
|
24 |
+
{"role": "user", "content": user_input},
|
25 |
+
]
|
26 |
+
outputs = pipeline_model(messages, max_new_tokens=256)
|
27 |
+
return outputs[0]["generated_text"]
|
28 |
|
29 |
# Crear la interfaz de Gradio
|
30 |
gr.Interface(fn=respond_to_query, inputs="text", outputs="text").launch()
|
31 |
+
|