Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForSequenceClassification
|
2 |
+
from transformers import AutoTokenizer
|
3 |
+
|
4 |
+
|
5 |
+
def main():
|
6 |
+
st.title("yelp2024fall Test")
|
7 |
+
st.write("Enter a sentence for analysis:")
|
8 |
+
user_input = st.text_input("")
|
9 |
+
if user_input:
|
10 |
+
# Approach: AutoModel
|
11 |
+
model2 = AutoModelForSequenceClassification.from_pretrained("huimanho/CustomModel_yelp",
|
12 |
+
num_labels=5)
|
13 |
+
sentiment_pipeline = pipeline(model="huimanho/CustomModel_yelp")
|
14 |
+
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
|
15 |
+
outputs = model2(**inputs)
|
16 |
+
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
17 |
+
predictions = predictions.cpu().detach().numpy()
|
18 |
+
# Get the index of the largest output value
|
19 |
+
max_index = np.argmax(predictions)
|
20 |
+
st.write(f"result (AutoModel) - Label: {max_index}")
|
21 |
+
if __name__ == "__main__":
|
22 |
+
main()
|