Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,29 @@
|
|
1 |
import gradio as gr
|
2 |
import spaces
|
3 |
import torch
|
|
|
4 |
|
|
|
5 |
zero = torch.Tensor([0]).cuda()
|
6 |
-
print(zero.device)
|
|
|
|
|
|
|
7 |
|
8 |
@spaces.GPU
|
9 |
-
def
|
10 |
-
print(zero.device)
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import spaces
|
3 |
import torch
|
4 |
+
from transformers import pipeline
|
5 |
|
6 |
+
# Prueba de disponibilidad de GPU
|
7 |
zero = torch.Tensor([0]).cuda()
|
8 |
+
print(zero.device) # Imprime el dispositivo actual, por ejemplo 'cpu' o 'cuda:0'
|
9 |
+
|
10 |
+
# Inicializa el pipeline de generación de texto en GPU (device=0)
|
11 |
+
pipe = pipeline("text-generation", model="aaditya/Llama3-OpenBioLLM-70B", device=0)
|
12 |
|
13 |
@spaces.GPU
|
14 |
+
def generate_response(prompt):
|
15 |
+
print(zero.device) # Ahora debería imprimir 'cuda:0'
|
16 |
+
# Genera texto a partir del prompt (ajusta max_length u otros parámetros según necesidad)
|
17 |
+
result = pipe(prompt, max_length=100)
|
18 |
+
return result[0]['generated_text']
|
19 |
+
|
20 |
+
# Configuración de la interfaz de Gradio
|
21 |
+
iface = gr.Interface(
|
22 |
+
fn=generate_response,
|
23 |
+
inputs=gr.Textbox(label="Introduce tu prompt", placeholder="Escribe aquí tu pregunta o indicación..."),
|
24 |
+
outputs=gr.Textbox(label="Respuesta generada"),
|
25 |
+
title="Generador de Texto con Llama3-OpenBioLLM-70B",
|
26 |
+
description="Ingresa un prompt y obtén una respuesta generada por el modelo Llama3-OpenBioLLM-70B."
|
27 |
+
)
|
28 |
|
29 |
+
iface.launch()
|
|