Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,15 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
-
#
|
|
|
|
|
|
|
|
|
|
| 5 |
model = pipeline(
|
| 6 |
"text-generation",
|
| 7 |
model="rish13/polymers",
|
| 8 |
-
device=
|
| 9 |
)
|
| 10 |
|
| 11 |
def generate_response(prompt):
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
+
# Check if a GPU is available
|
| 6 |
+
device = 0 if torch.cuda.is_available() else -1
|
| 7 |
+
|
| 8 |
+
# Load the text-generation pipeline with the appropriate device
|
| 9 |
model = pipeline(
|
| 10 |
"text-generation",
|
| 11 |
model="rish13/polymers",
|
| 12 |
+
device=device # Automatically use GPU if available, otherwise CPU
|
| 13 |
)
|
| 14 |
|
| 15 |
def generate_response(prompt):
|