rish13 commited on
Commit
3680a42
·
verified ·
1 Parent(s): 0e5d4be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -1,11 +1,15 @@
1
  import gradio as gr
2
  from transformers import pipeline
 
3
 
4
- # Load the model with optimization settings
 
 
 
5
  model = pipeline(
6
  "text-generation",
7
  model="rish13/polymers",
8
- device=0 # Use device=0 for GPU (if available), -1 for CPU
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):