Update app.py
Browse files
app.py
CHANGED
@@ -20,6 +20,7 @@ warnings.filterwarnings("ignore", category=InconsistentVersionWarning)
|
|
20 |
|
21 |
# Download NLTK resources
|
22 |
nltk.download('punkt', quiet=True)
|
|
|
23 |
nltk.download('wordnet', quiet=True)
|
24 |
nltk.download('omw-1.4', quiet=True)
|
25 |
|
@@ -60,7 +61,7 @@ class LuongAttention(tf.keras.layers.Layer):
|
|
60 |
return config
|
61 |
|
62 |
# Load model, tokenizer, label encoder from Hugging Face Hub
|
63 |
-
model_path = hf_hub_download(repo_id="logasanjeev/sentiment-analysis-bilstm-luong", filename="
|
64 |
tokenizer_path = hf_hub_download(repo_id="logasanjeev/sentiment-analysis-bilstm-luong", filename="tokenizer.json")
|
65 |
encoder_path = hf_hub_download(repo_id="logasanjeev/sentiment-analysis-bilstm-luong", filename="label_encoder.pkl")
|
66 |
model = load_model(model_path, custom_objects={"LuongAttention": LuongAttention})
|
@@ -117,7 +118,7 @@ def predict_sentiment(text):
|
|
117 |
cleaned
|
118 |
)
|
119 |
|
120 |
-
# Custom CSS for
|
121 |
css = """
|
122 |
body { font-family: 'Arial', sans-serif; }
|
123 |
.gradio-container { max-width: 800px; margin: auto; }
|
@@ -130,7 +131,7 @@ button { border-radius: 6px; }
|
|
130 |
"""
|
131 |
|
132 |
# Gradio interface
|
133 |
-
with gr.Blocks(theme=
|
134 |
gr.Markdown(
|
135 |
"""
|
136 |
# Sentiment Analysis App
|
@@ -146,8 +147,6 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
146 |
lines=2
|
147 |
)
|
148 |
predict_btn = gr.Button("Analyze Sentiment", variant="primary")
|
149 |
-
with gr.Column(scale=1):
|
150 |
-
theme_toggle = gr.Button("Toggle Theme")
|
151 |
|
152 |
output_text = gr.Markdown()
|
153 |
prob_plot = gr.Label(label="Probability Distribution")
|
@@ -164,21 +163,12 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
164 |
inputs=text_input
|
165 |
)
|
166 |
|
167 |
-
#
|
168 |
-
def toggle_theme():
|
169 |
-
return {"theme": gr.themes.Dark()} if demo.theme.name == "soft" else {"theme": gr.themes.Soft()}
|
170 |
-
|
171 |
-
# Bind functions
|
172 |
predict_btn.click(
|
173 |
fn=predict_sentiment,
|
174 |
inputs=text_input,
|
175 |
outputs=[output_text, prob_plot, cleaned_text]
|
176 |
)
|
177 |
-
theme_toggle.click(
|
178 |
-
fn=toggle_theme,
|
179 |
-
inputs=None,
|
180 |
-
outputs=[demo]
|
181 |
-
)
|
182 |
|
183 |
gr.Markdown(
|
184 |
"""
|
|
|
20 |
|
21 |
# Download NLTK resources
|
22 |
nltk.download('punkt', quiet=True)
|
23 |
+
nltk.download('punkt_tab', quiet=True)
|
24 |
nltk.download('wordnet', quiet=True)
|
25 |
nltk.download('omw-1.4', quiet=True)
|
26 |
|
|
|
61 |
return config
|
62 |
|
63 |
# Load model, tokenizer, label encoder from Hugging Face Hub
|
64 |
+
model_path = hf_hub_download(repo_id="logasanjeev/sentiment-analysis-bilstm-luong", filename="sentiment_model_v3.h5")
|
65 |
tokenizer_path = hf_hub_download(repo_id="logasanjeev/sentiment-analysis-bilstm-luong", filename="tokenizer.json")
|
66 |
encoder_path = hf_hub_download(repo_id="logasanjeev/sentiment-analysis-bilstm-luong", filename="label_encoder.pkl")
|
67 |
model = load_model(model_path, custom_objects={"LuongAttention": LuongAttention})
|
|
|
118 |
cleaned
|
119 |
)
|
120 |
|
121 |
+
# Custom CSS for sleek UI
|
122 |
css = """
|
123 |
body { font-family: 'Arial', sans-serif; }
|
124 |
.gradio-container { max-width: 800px; margin: auto; }
|
|
|
131 |
"""
|
132 |
|
133 |
# Gradio interface
|
134 |
+
with gr.Blocks(theme="soft", css=css) as demo:
|
135 |
gr.Markdown(
|
136 |
"""
|
137 |
# Sentiment Analysis App
|
|
|
147 |
lines=2
|
148 |
)
|
149 |
predict_btn = gr.Button("Analyze Sentiment", variant="primary")
|
|
|
|
|
150 |
|
151 |
output_text = gr.Markdown()
|
152 |
prob_plot = gr.Label(label="Probability Distribution")
|
|
|
163 |
inputs=text_input
|
164 |
)
|
165 |
|
166 |
+
# Bind predict function
|
|
|
|
|
|
|
|
|
167 |
predict_btn.click(
|
168 |
fn=predict_sentiment,
|
169 |
inputs=text_input,
|
170 |
outputs=[output_text, prob_plot, cleaned_text]
|
171 |
)
|
|
|
|
|
|
|
|
|
|
|
172 |
|
173 |
gr.Markdown(
|
174 |
"""
|