Spaces:
Runtime error
Runtime error
Commit
·
3880795
1
Parent(s):
2ea3452
Update app.py
Browse files
app.py
CHANGED
@@ -1,53 +1,12 @@
|
|
1 |
-
import
|
2 |
from transformers import pipeline
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
res_label["NEGATIVE"] = res["score"]
|
14 |
-
res_label["POSITIVE"] = 1 - res["score"]
|
15 |
-
return res_label
|
16 |
-
|
17 |
-
custom_css = """
|
18 |
-
#component-0 {
|
19 |
-
max-width: 600px;
|
20 |
-
margin: 0 auto;
|
21 |
-
}
|
22 |
-
|
23 |
-
h1,h2 {
|
24 |
-
text-align: center;
|
25 |
-
}
|
26 |
-
|
27 |
-
a {
|
28 |
-
color: #77b3ee !important;
|
29 |
-
text-decoration: none !important;
|
30 |
-
}
|
31 |
-
|
32 |
-
a:hover {
|
33 |
-
text-decoration: underline !important;
|
34 |
-
}
|
35 |
-
"""
|
36 |
-
|
37 |
-
browser_tab_title = "Sentiment Analysis"
|
38 |
-
intro_markdown = """## Sentiment Analysis
|
39 |
-
|
40 |
-
Using the [distilbert-base-uncased-finetuned-sst-2-english](https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english) model, trained on movie reviews."""
|
41 |
-
|
42 |
-
with gr.Blocks(title=browser_tab_title, css=custom_css) as demo:
|
43 |
-
with gr.Row():
|
44 |
-
with gr.Column():
|
45 |
-
title = gr.Markdown(intro_markdown)
|
46 |
-
text_input = gr.Textbox(placeholder="Enter a positive or negative sentence here...", label="Text")
|
47 |
-
label_output = gr.Label(label="Sentiment outcome")
|
48 |
-
button_run = gr.Button("Compute sentiment")
|
49 |
-
button_run.click(sentiment_analysis, inputs=text_input, outputs=label_output)
|
50 |
-
gr.Examples(["That's great!", "The movie was bad.", "How are you"], text_input)
|
51 |
-
|
52 |
-
if __name__ == "__main__":
|
53 |
-
demo.launch()
|
|
|
1 |
+
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
+
from textblob import TextBlob
|
4 |
+
|
5 |
+
pipe = pipeline('sentiment-analysis')
|
6 |
+
st.title("Hugging Face Sentiment Analysis Spaces Example")
|
7 |
+
st.subheader("What framework would you like to use for Sentiment Analysis")
|
8 |
+
#Picking what NLP task you want to do
|
9 |
+
option = st.selectbox('Framework',('Transformers', 'TextBlob')) #option is stored in this variable
|
10 |
+
#Textbox for text user is entering
|
11 |
+
st.subheader("Enter the text you'd like to analyze.")
|
12 |
+
text = st.text_input('Enter text') #text is stored in this variable
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|