Spaces:
Sleeping
Sleeping
Upload 1_Movie_Reviews.py
Browse files- pages/1_Movie_Reviews.py +68 -0
pages/1_Movie_Reviews.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.set_page_config(page_title="Turkish Review Analysis - via AG", page_icon='📖')
|
4 |
+
st.header("📖Movie Review Analysis - TR")
|
5 |
+
|
6 |
+
with st.sidebar:
|
7 |
+
hf_key = st.text_input("HuggingFace Access Key", key="hf_key", type="password")
|
8 |
+
|
9 |
+
MODEL_MOVIE = {
|
10 |
+
"albert": "anilguven/albert_tr_turkish_movie_reviews", # Add the emoji for the Meta-Llama model
|
11 |
+
"distilbert": "anilguven/distilbert_tr_turkish_movie_reviews",
|
12 |
+
"bert": "anilguven/bert_tr_turkish_movie_reviews",
|
13 |
+
"electra": "anilguven/electra_tr_turkish_movie_reviews",
|
14 |
+
}
|
15 |
+
|
16 |
+
MODEL_MOVIES = ["albert","distilbert","bert","electra"]
|
17 |
+
|
18 |
+
# Use a pipeline as a high-level helper
|
19 |
+
from transformers import pipeline
|
20 |
+
# Create a mapping from formatted model names to their original identifiers
|
21 |
+
def format_model_name(model_key):
|
22 |
+
name_parts = model_key
|
23 |
+
formatted_name = ''.join(name_parts) # Join them into a single string with title case
|
24 |
+
return formatted_name
|
25 |
+
|
26 |
+
formatted_names_to_identifiers = {
|
27 |
+
format_model_name(key): key for key in MODEL_MOVIE.keys()
|
28 |
+
}
|
29 |
+
|
30 |
+
with st.expander("About this app"):
|
31 |
+
st.write(f"""
|
32 |
+
1-Choose your model for movie review analysis (negative or positive).\n
|
33 |
+
2-Enter your sample text.\n
|
34 |
+
3-And model predict your text's result.
|
35 |
+
""")
|
36 |
+
|
37 |
+
# Debug to ensure names are formatted correctly
|
38 |
+
#st.write("Formatted Model Names to Identifiers:", formatted_names_to_identifiers)
|
39 |
+
|
40 |
+
model_name: str = st.selectbox("Model", options=MODEL_MOVIES)
|
41 |
+
selected_model = MODEL_MOVIE[model_name]
|
42 |
+
|
43 |
+
if not hf_key:
|
44 |
+
st.info("Please add your HuggingFace Access Key to continue.")
|
45 |
+
st.stop()
|
46 |
+
|
47 |
+
access_token = hf_key
|
48 |
+
pipe = pipeline("text-classification", model=selected_model, token=access_token)
|
49 |
+
|
50 |
+
#from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
51 |
+
#tokenizer = AutoTokenizer.from_pretrained(selected_model)
|
52 |
+
#pipe = AutoModelForSequenceClassification.from_pretrained(pretrained_model_name_or_path=selected_model)
|
53 |
+
|
54 |
+
comment = st.text_input("Enter your text for analysis")#User input
|
55 |
+
|
56 |
+
st.text('')
|
57 |
+
if st.button("Submit for Analysis"):#User Review Button
|
58 |
+
if not hf_key:
|
59 |
+
st.info("Please add your HuggingFace Access Key to continue.")
|
60 |
+
st.stop()
|
61 |
+
else:
|
62 |
+
result = pipe(comment)[0]
|
63 |
+
label=''
|
64 |
+
if result["label"] == "LABEL_0": label = "Negative"
|
65 |
+
else: label = "Positive"
|
66 |
+
st.text(label + " comment with " + str(result["score"]) + " accuracy")
|
67 |
+
|
68 |
+
|