Update app.py
Browse files
app.py
CHANGED
@@ -21,24 +21,24 @@ try:
|
|
21 |
|
22 |
model1 = pipeline("text-classification", model=model1_name)
|
23 |
test_output1 = model1("Testing the first model with a simple sentence.")
|
24 |
-
print("
|
25 |
|
26 |
model2 = pipeline("text-classification", model=model2_name)
|
27 |
test_output2 = model2("Testing the second model with a simple sentence.")
|
28 |
-
print("
|
29 |
except Exception as e:
|
30 |
print(f"Failed to load or run models: {e}")
|
31 |
|
32 |
# Prediction function with model selection and error handling
|
33 |
def predict_sentiment(text, model_choice):
|
34 |
try:
|
35 |
-
if model_choice == "
|
36 |
if model1 is None:
|
37 |
-
raise ValueError("
|
38 |
predictions = model1(text)
|
39 |
-
elif model_choice == "
|
40 |
if model2 is None:
|
41 |
-
raise ValueError("
|
42 |
predictions = model2(text)
|
43 |
else:
|
44 |
raise ValueError("Invalid model choice.")
|
@@ -49,11 +49,11 @@ def predict_sentiment(text, model_choice):
|
|
49 |
|
50 |
# Define example inputs
|
51 |
examples = [
|
52 |
-
["I absolutely love this product! It has changed my life.", "
|
53 |
-
["This is the worst movie I have ever seen. Completely disappointing.", "
|
54 |
-
["I'm not sure how I feel about this new update. It has some good points, but also many drawbacks.", "
|
55 |
-
["The customer service was fantastic! Very helpful and polite.", "
|
56 |
-
["Honestly, this was quite a mediocre experience. Nothing special.", "
|
57 |
]
|
58 |
|
59 |
# Gradio interface setup
|
@@ -63,7 +63,7 @@ iface = gr.Interface(
|
|
63 |
description="Enter text to analyze sentiment. Powered by Hugging Face Transformers.",
|
64 |
inputs=[
|
65 |
gr.Textbox(lines=2, placeholder="Enter text here..."),
|
66 |
-
gr.Radio(choices=["
|
67 |
],
|
68 |
outputs="text",
|
69 |
examples=examples
|
|
|
21 |
|
22 |
model1 = pipeline("text-classification", model=model1_name)
|
23 |
test_output1 = model1("Testing the first model with a simple sentence.")
|
24 |
+
print("Harassment Detector test output:", test_output1)
|
25 |
|
26 |
model2 = pipeline("text-classification", model=model2_name)
|
27 |
test_output2 = model2("Testing the second model with a simple sentence.")
|
28 |
+
print("Depressive Detector test output:", test_output2)
|
29 |
except Exception as e:
|
30 |
print(f"Failed to load or run models: {e}")
|
31 |
|
32 |
# Prediction function with model selection and error handling
|
33 |
def predict_sentiment(text, model_choice):
|
34 |
try:
|
35 |
+
if model_choice == "Harassment Detector":
|
36 |
if model1 is None:
|
37 |
+
raise ValueError("Harassment Detector not loaded.")
|
38 |
predictions = model1(text)
|
39 |
+
elif model_choice == "Depressive Detector":
|
40 |
if model2 is None:
|
41 |
+
raise ValueError("Depressive Detector not loaded.")
|
42 |
predictions = model2(text)
|
43 |
else:
|
44 |
raise ValueError("Invalid model choice.")
|
|
|
49 |
|
50 |
# Define example inputs
|
51 |
examples = [
|
52 |
+
["I absolutely love this product! It has changed my life.", "Harassment Detector"],
|
53 |
+
["This is the worst movie I have ever seen. Completely disappointing.", "Harassment Detector"],
|
54 |
+
["I'm not sure how I feel about this new update. It has some good points, but also many drawbacks.", "Depressive Detector"],
|
55 |
+
["The customer service was fantastic! Very helpful and polite.", "Depressive Detector"],
|
56 |
+
["Honestly, this was quite a mediocre experience. Nothing special.", "Harassment Detector"]
|
57 |
]
|
58 |
|
59 |
# Gradio interface setup
|
|
|
63 |
description="Enter text to analyze sentiment. Powered by Hugging Face Transformers.",
|
64 |
inputs=[
|
65 |
gr.Textbox(lines=2, placeholder="Enter text here..."),
|
66 |
+
gr.Radio(choices=["Harassment Detector", "Depressive Detector"], label="Select Model")
|
67 |
],
|
68 |
outputs="text",
|
69 |
examples=examples
|