peace4ever
commited on
Commit
•
b89d49a
1
Parent(s):
10bd220
Update app.py
Browse files
app.py
CHANGED
@@ -3,27 +3,52 @@ import streamlit as st
|
|
3 |
import torch as torch
|
4 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, AutoConfig
|
5 |
|
6 |
-
model_name = "peace4ever/roberta-large-finetuned-mongolian_v4"
|
7 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
-
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
output = model(**encoded_input)
|
13 |
|
14 |
-
|
|
|
|
|
15 |
|
16 |
-
#
|
17 |
-
|
18 |
-
|
19 |
-
config.id2label = {0: "positive", 1: "negative", 2: "neutral"}
|
20 |
-
config.save_pretrained(model_name)
|
21 |
|
22 |
-
predicted_label_id = torch.argmax(output.logits, dim=1).item()
|
23 |
-
id2label = model.config.id2label
|
24 |
-
predicted_label = id2label[predicted_label_id]
|
25 |
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
# st.json(predicted_label)
|
29 |
|
|
|
3 |
import torch as torch
|
4 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, AutoConfig
|
5 |
|
|
|
|
|
|
|
6 |
|
7 |
+
import requests
|
8 |
+
from transformers import pipeline
|
|
|
9 |
|
10 |
+
# Load the model using its ID or name
|
11 |
+
model_id_or_name = "peace4ever/roberta-large-finetuned-mongolian_v4" # Update with your model ID or name
|
12 |
+
classifier = pipeline("sentiment-analysis", model=model_id_or_name)
|
13 |
|
14 |
+
# Example usage
|
15 |
+
result = classifier("I loved Star Wars so much!")
|
16 |
+
print(result)
|
|
|
|
|
17 |
|
|
|
|
|
|
|
18 |
|
19 |
+
# API_URL = "https://api-inference.huggingface.co/models/peace4ever/roberta-large-finetuned-mongolian_v4"
|
20 |
+
#
|
21 |
+
|
22 |
+
# def query(payload):
|
23 |
+
# response = requests.post(API_URL, headers=headers, json=payload)
|
24 |
+
# return response.json()
|
25 |
+
|
26 |
+
# output = query({
|
27 |
+
# "inputs": "I like you. I love you",
|
28 |
+
# })
|
29 |
+
|
30 |
+
|
31 |
+
# model_name = "peace4ever/roberta-large-finetuned-mongolian_v4"
|
32 |
+
# tokenizer = AutoTokenizer.from_pretrained(model_name)
|
33 |
+
# model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
34 |
+
|
35 |
+
# text = st.text_area("Өгүүлбэр оруулна уу?")
|
36 |
+
# encoded_input = tokenizer(text, return_tensors="pt")
|
37 |
+
# output = model(**encoded_input)
|
38 |
+
|
39 |
+
# label_map = {"positive": 0, "negative": 1, "neutral": 2}
|
40 |
+
|
41 |
+
# # Update the model configuration with custom labels
|
42 |
+
# config = AutoConfig.from_pretrained(model_name)
|
43 |
+
# config.label2id = {"positive": 0, "negative": 1, "neutral": 2}
|
44 |
+
# config.id2label = {0: "positive", 1: "negative", 2: "neutral"}
|
45 |
+
# config.save_pretrained(model_name)
|
46 |
+
|
47 |
+
# predicted_label_id = torch.argmax(output.logits, dim=1).item()
|
48 |
+
# id2label = model.config.id2label
|
49 |
+
# predicted_label = id2label[predicted_label_id]
|
50 |
+
|
51 |
+
# print("Predicted Class:", predicted_label)
|
52 |
|
53 |
# st.json(predicted_label)
|
54 |
|