runaksh commited on
Commit
627db32
1 Parent(s): b831a71

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +84 -0
app.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Hugging Face's logo
2
+ Hugging Face
3
+ Search models, datasets, users...
4
+ Models
5
+ Datasets
6
+ Spaces
7
+ Docs
8
+ Solutions
9
+ Pricing
10
+
11
+
12
+
13
+ Spaces:
14
+
15
+ runaksh
16
+ /
17
+ Symptom-2-disease_Text_Classification
18
+
19
+
20
+ like
21
+ 0
22
+
23
+ Logs
24
+ App
25
+ Files
26
+ Community
27
+ Settings
28
+ Symptom-2-disease_Text_Classification
29
+ /
30
+ app.py
31
+ runaksh's picture
32
+ runaksh
33
+ Update app.py
34
+ 7450a2c
35
+ about 2 months ago
36
+ raw
37
+ history
38
+ blame
39
+ edit
40
+ delete
41
+ No virus
42
+ 1.33 kB
43
+ # -*- coding: utf-8 -*-
44
+ """gradio_deploy.ipynb
45
+ Automatically generated by Colaboratory.
46
+ """
47
+ import os
48
+ import gradio
49
+ from PIL import Image
50
+ from timeit import default_timer as timer
51
+ from tensorflow import keras
52
+ import torch
53
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
54
+ import numpy as np
55
+
56
+ loaded_model = AutoModelForSequenceClassification.from_pretrained("runaksh/financial_sentiment_distilBERT")
57
+ loaded_tokenizer = AutoTokenizer.from_pretrained("runaksh/financial_sentiment_distilBERT")
58
+
59
+ # Function for class prediction
60
+ def predict(sample, validate=True):
61
+ classifier = pipeline("text-classification", model=loaded_model, tokenizer=loaded_tokenizer)
62
+ pred = classifier(sample)[0]['label']
63
+ return pred
64
+
65
+ title = "Financial Sentiment Classification"
66
+ description = "Enter the news"
67
+
68
+ # Gradio elements
69
+
70
+ # Input from user
71
+ in_prompt = gradio.components.Textbox(lines=2, label='Enter the News')
72
+
73
+ # Output response
74
+ out_response = gradio.components.Textbox(label='Sentiment')
75
+
76
+ # Gradio interface to generate UI link
77
+ iface = gradio.Interface(fn=predict,
78
+ inputs = in_prompt,
79
+ outputs = out_response,
80
+ title=title,
81
+ description=description
82
+ )
83
+
84
+ iface.launch(debug = True)