Spaces:
Build error
Build error
Upload 4 files
Browse files
README.md
CHANGED
|
@@ -1,13 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 4.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
-
license: apache-2.0
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Stress Prediction Model
|
| 3 |
+
emoji: 💻
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: yellow
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.26.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from PIL import Image
|
| 4 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 5 |
+
|
| 6 |
+
js = """
|
| 7 |
+
function createGradioAnimation() {
|
| 8 |
+
var container = document.createElement('div');
|
| 9 |
+
container.id = 'gradio-animation';
|
| 10 |
+
container.style.fontSize = '2em';
|
| 11 |
+
container.style.fontWeight = 'bold';
|
| 12 |
+
container.style.textAlign = 'center';
|
| 13 |
+
container.style.marginBottom = '20px';
|
| 14 |
+
|
| 15 |
+
var text = 'Stress Prediction Model';
|
| 16 |
+
for (var i = 0; i < text.length; i++) {
|
| 17 |
+
(function(i){
|
| 18 |
+
setTimeout(function(){
|
| 19 |
+
var letter = document.createElement('span');
|
| 20 |
+
letter.style.opacity = '0';
|
| 21 |
+
letter.style.transition = 'opacity 0.5s';
|
| 22 |
+
letter.innerText = text[i];
|
| 23 |
+
|
| 24 |
+
container.appendChild(letter);
|
| 25 |
+
|
| 26 |
+
setTimeout(function() {
|
| 27 |
+
letter.style.opacity = '1';
|
| 28 |
+
}, 50);
|
| 29 |
+
}, i * 250);
|
| 30 |
+
})(i);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
var gradioContainer = document.querySelector('.gradio-container');
|
| 34 |
+
gradioContainer.insertBefore(container, gradioContainer.firstChild);
|
| 35 |
+
|
| 36 |
+
return 'Animation created';
|
| 37 |
+
}
|
| 38 |
+
"""
|
| 39 |
+
|
| 40 |
+
saved_directory = 'jnyx74/stress-prediction'
|
| 41 |
+
tokenizer = AutoTokenizer.from_pretrained(saved_directory)
|
| 42 |
+
model = AutoModelForSequenceClassification.from_pretrained(saved_directory)
|
| 43 |
+
|
| 44 |
+
# gr.load("models/jnyx74/stress-prediction").launch()
|
| 45 |
+
|
| 46 |
+
#"LABEL_0": "I think you don't feel stress. Perhaps, describe more, so I can understand you more!",
|
| 47 |
+
#"LABEL_1": "Darling, I sensed that you were stressed. Are you alright?""
|
| 48 |
+
|
| 49 |
+
background = Image.open('quote.jpg')
|
| 50 |
+
with gr.Blocks(js=js,theme=gr.themes.Soft()) as demo:
|
| 51 |
+
gr.Image(background, height = '400px',interactive = False)
|
| 52 |
+
gr.Markdown(
|
| 53 |
+
'''
|
| 54 |
+
# Let me study you, perhaps?
|
| 55 |
+
Not everyone tends to express/ knowing to relieve their stress in a proper way. Therefore, are you stress? Perhaps,
|
| 56 |
+
I could have a guess here. I am a fine-tuned DeepLearning/Transformers Model on DistilBert Model with training on reddit datasets.
|
| 57 |
+
'''
|
| 58 |
+
)
|
| 59 |
+
gr.Markdown("Start typing below and then click **Study Me** to see the output.")
|
| 60 |
+
inp = gr.Text(placeholder = "How do you feel today?", label="Sentence Me:")
|
| 61 |
+
btn = gr.Button("Study Me")
|
| 62 |
+
with gr.Column(visible=False) as output_col:
|
| 63 |
+
out_label = gr.Markdown("# Ooh, I think ...")
|
| 64 |
+
out = gr.Text(label="Result",interactive = False)
|
| 65 |
+
examples = gr.Examples(examples=["By serendipity, I meet her once again and for real, I miss her.",
|
| 66 |
+
"Insomnia and overthinking is really killing me as my final year project is reaching.",
|
| 67 |
+
"I just won a lottery and wanting to own a house in Kuching.",
|
| 68 |
+
"I can't believe I just hit a car just now and the car driver just ran away, how ridiculous?",
|
| 69 |
+
"I hate kids but my wife insists to have one, can't we just adopt?"]
|
| 70 |
+
,
|
| 71 |
+
inputs = [inp])
|
| 72 |
+
|
| 73 |
+
def form_submit(inp):
|
| 74 |
+
if len(inp)<=15:
|
| 75 |
+
gr.Warning("Describe/ Express more, a sentence with expression is more appreciated")
|
| 76 |
+
return {
|
| 77 |
+
output_col: gr.Column(visible=True),
|
| 78 |
+
out: gr.Text(value="Please express more of you!!")}
|
| 79 |
+
else:
|
| 80 |
+
inputs = tokenizer([inp], return_tensors="pt")
|
| 81 |
+
with torch.no_grad():
|
| 82 |
+
logits = model(**inputs).logits
|
| 83 |
+
|
| 84 |
+
predicted_class_id = logits.argmax().item()
|
| 85 |
+
result = model.config.id2label[predicted_class_id]
|
| 86 |
+
if result == 'LABEL_0':
|
| 87 |
+
result_value = "I think you don't feel stress. Perhaps, describe more, so I can understand you more!"
|
| 88 |
+
else: result_value = "Darling, I sensed that you were stressed. Are you alright?"
|
| 89 |
+
gr.Info("Success Executed")
|
| 90 |
+
return {
|
| 91 |
+
output_col: gr.Column(visible=True),
|
| 92 |
+
out: gr.Text(value=result_value)
|
| 93 |
+
}
|
| 94 |
+
btn.click(fn=form_submit, inputs=inp, outputs=[out, output_col])
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
demo.launch()
|
quote.jpg
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
torch
|
| 3 |
+
transformers
|
| 4 |
+
nltk
|