Commit
•
02c7de4
1
Parent(s):
4c2f375
Update app.py
Browse files
app.py
CHANGED
@@ -1,42 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification, AutoConfig
|
5 |
|
|
|
6 |
|
7 |
-
|
8 |
-
# from transformers import pipeline
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
# classifier = pipeline("sentiment-analysis", model=model_id_or_name)
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
|
|
|
|
|
|
|
18 |
|
19 |
-
model_name = "peace4ever/roberta-large-finetuned-mongolian_v3"
|
20 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
21 |
-
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
22 |
|
23 |
-
text = st.text_area("Өгүүлбэр оруулна уу?")
|
24 |
-
encoded_input = tokenizer(text, return_tensors="pt")
|
25 |
-
output = model(**encoded_input)
|
26 |
|
27 |
-
label_map = {"positive": 0, "negative": 1, "neutral": 2}
|
28 |
|
29 |
-
# Update the model configuration with custom labels
|
30 |
-
config = AutoConfig.from_pretrained(model_name)
|
31 |
-
config.label2id = {"positive": 0, "negative": 1, "neutral": 2}
|
32 |
-
config.id2label = {0: "positive", 1: "negative", 2: "neutral"}
|
33 |
-
config.save_pretrained(model_name)
|
34 |
|
35 |
-
predicted_label_id = torch.argmax(output.logits, dim=1).item()
|
36 |
-
id2label = model.config.id2label
|
37 |
-
predicted_label = id2label[predicted_label_id]
|
38 |
|
39 |
-
print("Predicted Class:", predicted_label)
|
40 |
|
41 |
# st.json(predicted_label)
|
42 |
|
|
|
1 |
+
# import streamlit as st
|
2 |
+
|
3 |
+
# import torch as torch
|
4 |
+
# from transformers import AutoTokenizer, AutoModelForSequenceClassification, AutoConfig
|
5 |
+
|
6 |
+
|
7 |
import streamlit as st
|
8 |
+
from transformers import pipeline
|
9 |
+
from PIL import Image
|
10 |
|
11 |
+
pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
|
|
|
12 |
|
13 |
+
st.title("Hot Dog? Or Not?")
|
14 |
|
15 |
+
file_name = st.file_uploader("Upload a hot dog candidate image")
|
|
|
16 |
|
17 |
+
if file_name is not None:
|
18 |
+
col1, col2 = st.columns(2)
|
|
|
19 |
|
20 |
+
image = Image.open(file_name)
|
21 |
+
col1.image(image, use_column_width=True)
|
22 |
+
predictions = pipeline(image)
|
23 |
|
24 |
+
col2.header("Probabilities")
|
25 |
+
for p in predictions:
|
26 |
+
col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%")
|
27 |
|
28 |
+
# model_name = "peace4ever/roberta-large-finetuned-mongolian_v3"
|
29 |
+
# tokenizer = AutoTokenizer.from_pretrained(model_name)
|
30 |
+
# model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
31 |
|
32 |
+
# text = st.text_area("Өгүүлбэр оруулна уу?")
|
33 |
+
# encoded_input = tokenizer(text, return_tensors="pt")
|
34 |
+
# output = model(**encoded_input)
|
35 |
|
36 |
+
# label_map = {"positive": 0, "negative": 1, "neutral": 2}
|
37 |
|
38 |
+
# # Update the model configuration with custom labels
|
39 |
+
# config = AutoConfig.from_pretrained(model_name)
|
40 |
+
# config.label2id = {"positive": 0, "negative": 1, "neutral": 2}
|
41 |
+
# config.id2label = {0: "positive", 1: "negative", 2: "neutral"}
|
42 |
+
# config.save_pretrained(model_name)
|
43 |
|
44 |
+
# predicted_label_id = torch.argmax(output.logits, dim=1).item()
|
45 |
+
# id2label = model.config.id2label
|
46 |
+
# predicted_label = id2label[predicted_label_id]
|
47 |
|
48 |
+
# print("Predicted Class:", predicted_label)
|
49 |
|
50 |
# st.json(predicted_label)
|
51 |
|