Spaces:
Runtime error
Runtime error
switching to streamlit for demonstration purposes
Browse files
app.py
CHANGED
|
@@ -1,19 +1,42 @@
|
|
| 1 |
-
import streamlit as st
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
-
import
|
|
|
|
| 4 |
|
| 5 |
-
st.header("Sentiment-demo-app")
|
| 6 |
-
st.subheader("Please be patient and wait up to a minute until the demo app is loaded.")
|
| 7 |
-
st.caption("This is a very simple demo application for a zero-shot classification pipeline to classify positive, neutral, or negative sentiment for a short text. Enter your text in the box below and press CTRl+ENTER to run the model.")
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
#candidate_labels = ['Positive', 'Neutral', 'Negative']
|
| 13 |
-
result = pipe(texts)
|
| 14 |
|
| 15 |
-
if text:
|
| 16 |
-
out = pipe(text, result)
|
| 17 |
-
st.json(out)
|
| 18 |
-
del out
|
| 19 |
-
gc.collect()
|
|
|
|
| 1 |
+
#import streamlit as st
|
| 2 |
+
import gradio as gr
|
| 3 |
from transformers import pipeline
|
| 4 |
+
from huggingface_hub import InferenceClient
|
| 5 |
+
#import gc
|
| 6 |
|
| 7 |
+
#st.header("Sentiment-demo-app")
|
| 8 |
+
#st.subheader("Please be patient and wait up to a minute until the demo app is loaded.")
|
| 9 |
+
#st.caption("This is a very simple demo application for a zero-shot classification pipeline to classify positive, neutral, or negative sentiment for a short text. Enter your text in the box below and press CTRl+ENTER to run the model.")
|
| 10 |
|
| 11 |
+
title = "Sentiment-demo-app"
|
| 12 |
+
description = """This is a very simple demo application for a zero-shot classification pipeline to classify positive, neutral, or negative sentiment for a short text. Enter your text in the box below and press CTRl+ENTER to run the model.
|
| 13 |
+
Please be patient until the demo app is loaded. """
|
| 14 |
|
| 15 |
+
sentiment = pipeline("text-classification", model='tabularisai/multilingual-sentiment-analysis') #"zero-shot-classification" model='facebook/bart-large-mnli')
|
| 16 |
+
|
| 17 |
+
def get_sentiment(text):
|
| 18 |
+
output = sentiment(text)
|
| 19 |
+
return f'The sentence was classified as "{output[0]["label"]}" with {output[0]["score"]*100}% confidence'
|
| 20 |
+
|
| 21 |
+
demo = gr.Interface(
|
| 22 |
+
fn=get_sentiment,
|
| 23 |
+
inputs="text",
|
| 24 |
+
outputs="text",
|
| 25 |
+
title=title,
|
| 26 |
+
description=description
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
if __name__ == "__main__":
|
| 31 |
+
demo.launch()
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
#texts = st.text_area('Enter text here!')
|
| 35 |
#candidate_labels = ['Positive', 'Neutral', 'Negative']
|
| 36 |
+
#result = pipe(texts)
|
| 37 |
|
| 38 |
+
#if text:
|
| 39 |
+
# out = pipe(text, result)
|
| 40 |
+
# st.json(out)
|
| 41 |
+
# del out
|
| 42 |
+
# gc.collect()
|