JimminDev commited on
Commit
83702df
·
verified ·
1 Parent(s): 0a5568a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
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("Model 1 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("Model 2 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 == "Model 1":
36
  if model1 is None:
37
- raise ValueError("Model 1 not loaded.")
38
  predictions = model1(text)
39
- elif model_choice == "Model 2":
40
  if model2 is None:
41
- raise ValueError("Model 2 not loaded.")
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.", "Model 1"],
53
- ["This is the worst movie I have ever seen. Completely disappointing.", "Model 1"],
54
- ["I'm not sure how I feel about this new update. It has some good points, but also many drawbacks.", "Model 2"],
55
- ["The customer service was fantastic! Very helpful and polite.", "Model 2"],
56
- ["Honestly, this was quite a mediocre experience. Nothing special.", "Model 1"]
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=["Model 1", "Model 2"], label="Select Model")
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