Maram-almasary commited on
Commit
3d2863d
·
verified ·
1 Parent(s): c650b28

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -1,9 +1,15 @@
1
  import gradio as gr
2
  from transformers import pipeline
 
 
 
 
 
3
 
4
  # Load the sentiment analysis pipeline from Hugging Face
5
  model = pipeline("sentiment-analysis",
6
- model="nlptown/bert-base-multilingual-uncased-sentiment")
 
7
 
8
  # Function to get sentiment prediction
9
  def analyze_sentiment(text):
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ import torch
4
+
5
+ # Detect GPU availability and set the device
6
+ device = 0 if torch.cuda.is_available() else -1
7
+ print(f"Using device: {'GPU' if torch.cuda.is_available() else 'CPU'}")
8
 
9
  # Load the sentiment analysis pipeline from Hugging Face
10
  model = pipeline("sentiment-analysis",
11
+ model="nlptown/bert-base-multilingual-uncased-sentiment",
12
+ device=device)
13
 
14
  # Function to get sentiment prediction
15
  def analyze_sentiment(text):