dnzblgn commited on
Commit
e178bb5
·
verified ·
1 Parent(s): cdf1509

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -21
app.py CHANGED
@@ -27,42 +27,27 @@ def detect_sarcasm(sentence):
27
  predicted_class = torch.argmax(logits, dim=-1).item()
28
  return "Sarcasm" if predicted_class == 1 else "Not Sarcasm"
29
 
30
- # Combined function for text file pipeline
31
  def process_text_pipeline(text):
32
  sentences = text.split("\n") # Split text into multiple sentences
33
  processed_sentences = []
34
 
35
  for sentence in sentences:
36
  sentiment = analyze_sentiment(sentence.strip())
37
- if sentiment == "Positive":
 
 
38
  sarcasm_result = detect_sarcasm(sentence.strip())
39
  if sarcasm_result == "Sarcasm":
40
- processed_sentences.append(f"'{sentence}' -> Sentiment: Negative (due to sarcasm)")
41
  else:
42
  processed_sentences.append(f"'{sentence}' -> Sentiment: Positive")
43
- else:
44
- processed_sentences.append(f"'{sentence}' -> Sentiment: Negative")
45
 
46
  return "\n".join(processed_sentences)
47
 
48
- # Simple user interface for sarcasm detection
49
- def sarcasm_detection_interface(input_text):
50
- sentences = input_text.split("\n")
51
- predictions = []
52
-
53
- for sentence in sentences:
54
- sentiment = analyze_sentiment(sentence.strip())
55
- if sentiment == "Negative":
56
- predictions.append(f"'{sentence}' -> Not Sarcastic (Direct Negative Sentiment)")
57
- else:
58
- sarcasm_result = detect_sarcasm(sentence.strip())
59
- predictions.append(f"'{sentence}' -> {sarcasm_result}")
60
-
61
- return "\n".join(predictions)
62
-
63
  # Gradio UI
64
  interface = gr.Interface(
65
- fn=sarcasm_detection_interface,
66
  inputs=gr.Textbox(lines=10, placeholder="Enter one or more sentences, each on a new line."),
67
  outputs="text",
68
  title="Sarcasm Detection for Customer Reviews",
 
27
  predicted_class = torch.argmax(logits, dim=-1).item()
28
  return "Sarcasm" if predicted_class == 1 else "Not Sarcasm"
29
 
30
+ # Combined function for processing sentences
31
  def process_text_pipeline(text):
32
  sentences = text.split("\n") # Split text into multiple sentences
33
  processed_sentences = []
34
 
35
  for sentence in sentences:
36
  sentiment = analyze_sentiment(sentence.strip())
37
+ if sentiment == "Negative":
38
+ processed_sentences.append(f"'{sentence}' -> Sentiment: Negative")
39
+ else:
40
  sarcasm_result = detect_sarcasm(sentence.strip())
41
  if sarcasm_result == "Sarcasm":
42
+ processed_sentences.append(f"'{sentence}' -> Sentiment: Negative (Sarcastic Positive)")
43
  else:
44
  processed_sentences.append(f"'{sentence}' -> Sentiment: Positive")
 
 
45
 
46
  return "\n".join(processed_sentences)
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  # Gradio UI
49
  interface = gr.Interface(
50
+ fn=process_text_pipeline,
51
  inputs=gr.Textbox(lines=10, placeholder="Enter one or more sentences, each on a new line."),
52
  outputs="text",
53
  title="Sarcasm Detection for Customer Reviews",