Spaces:
No application file
No application file
Commit ·
9acd0fb
1
Parent(s): 63799b4
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,40 +0,0 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import transformers
|
| 3 |
-
import torch
|
| 4 |
-
|
| 5 |
-
# Define sentiment analysis models
|
| 6 |
-
models = {
|
| 7 |
-
"DistilBERT": transformers.pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english"),
|
| 8 |
-
"BERT": transformers.pipeline("sentiment-analysis", model="bert-base-uncased-finetuned-sst-2-english"),
|
| 9 |
-
"RoBERTa": transformers.pipeline("sentiment-analysis", model="roberta-base-openai-detector"),
|
| 10 |
-
}
|
| 11 |
-
|
| 12 |
-
# Define function to analyze sentiment using selected model
|
| 13 |
-
def analyze_sentiment(text, model_name):
|
| 14 |
-
model = models[model_name]
|
| 15 |
-
result = model(text)[0]
|
| 16 |
-
return result['label'], result['score']
|
| 17 |
-
|
| 18 |
-
# Define Streamlit app
|
| 19 |
-
def app():
|
| 20 |
-
st.title("Sentiment Analysis App")
|
| 21 |
-
|
| 22 |
-
# User input
|
| 23 |
-
text = st.text_area("Enter text to analyze", max_chars=1024)
|
| 24 |
-
|
| 25 |
-
# Sentiment analysis
|
| 26 |
-
if st.button("Analyze"):
|
| 27 |
-
st.write("Analyzing sentiment...")
|
| 28 |
-
with st.spinner("Wait for it..."):
|
| 29 |
-
results = []
|
| 30 |
-
for model_name in models:
|
| 31 |
-
label, score = analyze_sentiment(text, model_name)
|
| 32 |
-
results.append((model_name, label, score))
|
| 33 |
-
st.success("Sentiment analysis complete!")
|
| 34 |
-
st.write("Results:")
|
| 35 |
-
for model_name, label, score in results:
|
| 36 |
-
st.write(f"- {model_name}: {label} ({score:.2f})")
|
| 37 |
-
|
| 38 |
-
# Run Streamlit app
|
| 39 |
-
if __name__ == "__main__":
|
| 40 |
-
app()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|