Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,20 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
-
from transformers import AutoModelForSequenceClassification
|
4 |
-
from transformers import AutoTokenizer
|
5 |
-
import torch
|
6 |
-
import numpy as np
|
7 |
|
8 |
def main():
|
9 |
-
|
10 |
-
|
|
|
|
|
11 |
|
12 |
user_input = st.text_input("")
|
13 |
if user_input:
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
|
18 |
-
|
19 |
-
inputs = tokenizer(user_input,
|
20 |
-
padding=True,
|
21 |
-
truncation=True,
|
22 |
-
return_tensors='pt')
|
23 |
-
|
24 |
-
outputs = model2(**inputs)
|
25 |
-
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
26 |
-
predictions = predictions.cpu().detach().numpy()
|
27 |
-
# Get the index of the largest output value
|
28 |
-
max_index = np.argmax(predictions)
|
29 |
-
st.write(f"result (AutoModel) - Label: {max_index}")
|
30 |
|
|
|
|
|
31 |
|
32 |
if __name__ == "__main__":
|
33 |
main()
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
3 |
|
4 |
def main():
|
5 |
+
sentiment_pipeline = pipeline(model="isom5240/2025SpringL2")
|
6 |
+
|
7 |
+
st.title("Sentiment Analysis with HuggingFace Spaces")
|
8 |
+
st.write("Enter a sentence to analyze its sentiment:")
|
9 |
|
10 |
user_input = st.text_input("")
|
11 |
if user_input:
|
12 |
+
result = sentiment_pipeline(user_input)
|
13 |
+
sentiment = result[0]["label"]
|
14 |
+
confidence = result[0]["score"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
st.write(f"Sentiment: {sentiment}")
|
17 |
+
st.write(f"Confidence: {confidence:.2f}")
|
18 |
|
19 |
if __name__ == "__main__":
|
20 |
main()
|