qisan commited on
Commit
44dda57
1 Parent(s): 7687d77

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -8,6 +8,8 @@ import torch
8
  from huggingface_hub import hf_hub_download
9
  import transformers
10
  from transformers import BertModel, BertTokenizer
 
 
11
 
12
  class_names = ['Not Depressed', 'Depressed']
13
  pt_file = hf_hub_download(repo_id="liangc40/sentimental_analysis", filename="model.pt")
@@ -36,11 +38,12 @@ def analyse(text):
36
  pad_to_max_length=True,
37
  return_attention_mask=True,
38
  return_tensors='pt')
39
-
40
  outputs = model(input_ids = encoding['input_ids'], attention_mask = encoding['attention_mask'])
41
  _, preds = torch.max(outputs, dim=1)
 
42
  #print(preds)
43
- return preds
44
 
45
  with gr.Blocks() as demo:
46
  gr.Markdown("<h1><center>Sentiment Analysis with Fine-tuned BERT Model")
 
8
  from huggingface_hub import hf_hub_download
9
  import transformers
10
  from transformers import BertModel, BertTokenizer
11
+ from PIL import Image
12
+ import requests
13
 
14
  class_names = ['Not Depressed', 'Depressed']
15
  pt_file = hf_hub_download(repo_id="liangc40/sentimental_analysis", filename="model.pt")
 
38
  pad_to_max_length=True,
39
  return_attention_mask=True,
40
  return_tensors='pt')
41
+ face_url = "https://raw.githubusercontent.com/liangc40/ID2223_Sentimental_Analysis_Project/main/Image/"+ str(preds) + ".png"
42
  outputs = model(input_ids = encoding['input_ids'], attention_mask = encoding['attention_mask'])
43
  _, preds = torch.max(outputs, dim=1)
44
+ img = Image.open(requests.get(face_url, stream=True).raw)
45
  #print(preds)
46
+ return img
47
 
48
  with gr.Blocks() as demo:
49
  gr.Markdown("<h1><center>Sentiment Analysis with Fine-tuned BERT Model")