Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -31,29 +31,61 @@ def detect_sarcasm(sentence):
|
|
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 |
-
|
|
|
|
|
|
|
|
|
37 |
if sentiment == "Negative":
|
38 |
-
processed_sentences.append(f"'{sentence}' -> Sentiment: Negative")
|
39 |
else:
|
40 |
-
sarcasm_result = detect_sarcasm(sentence
|
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 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
# Run the interface
|
58 |
if __name__ == "__main__":
|
59 |
-
interface.launch()
|
|
|
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 |
+
sentence = sentence.strip()
|
37 |
+
if not sentence:
|
38 |
+
continue # Skip empty lines
|
39 |
+
|
40 |
+
sentiment = analyze_sentiment(sentence)
|
41 |
if sentiment == "Negative":
|
42 |
+
processed_sentences.append(f"β '{sentence}' -> Sentiment: Negative")
|
43 |
else:
|
44 |
+
sarcasm_result = detect_sarcasm(sentence)
|
45 |
if sarcasm_result == "Sarcasm":
|
46 |
+
processed_sentences.append(f"β οΈ '{sentence}' -> Sentiment: Negative (Sarcastic Positive)")
|
47 |
else:
|
48 |
+
processed_sentences.append(f"β
'{sentence}' -> Sentiment: Positive")
|
49 |
+
|
50 |
return "\n".join(processed_sentences)
|
51 |
|
52 |
+
# Improved Gradio UI
|
53 |
+
with gr.Blocks(css=".gradio-container {background-color: #f3f4f6; color: #333; font-family: 'Arial';}") as interface:
|
54 |
+
gr.Markdown(
|
55 |
+
"""
|
56 |
+
<h1 style='text-align: center; font-size: 36px;'>π Sarcasm Detection for Customer Reviews π</h1>
|
57 |
+
<p style='text-align: center; font-size: 18px;'>This web app analyzes customer reviews for sentiment and detects sarcasm in positive reviews.</p>
|
58 |
+
"""
|
59 |
+
)
|
60 |
+
|
61 |
+
with gr.Tab("Text Input"):
|
62 |
+
with gr.Row():
|
63 |
+
text_input = gr.Textbox(
|
64 |
+
lines=10,
|
65 |
+
label="Enter Sentences",
|
66 |
+
placeholder="Enter one or more sentences, each on a new line."
|
67 |
+
)
|
68 |
+
result_output = gr.Textbox(label="Results", lines=10, interactive=False)
|
69 |
+
analyze_button = gr.Button("π Analyze", elem_id="analyze-button")
|
70 |
+
|
71 |
+
analyze_button.click(process_text_pipeline, inputs=text_input, outputs=result_output)
|
72 |
+
|
73 |
+
with gr.Tab("Upload Text File"):
|
74 |
+
file_input = gr.File(label="Upload Text File")
|
75 |
+
file_output = gr.Textbox(label="Results", lines=10, interactive=False)
|
76 |
+
|
77 |
+
def process_file(file):
|
78 |
+
text = file.read().decode("utf-8")
|
79 |
+
return process_text_pipeline(text)
|
80 |
+
|
81 |
+
file_input.change(process_file, inputs=file_input, outputs=file_output)
|
82 |
+
|
83 |
+
gr.Markdown(
|
84 |
+
"""
|
85 |
+
<p style='text-align: center;'>Made with β€οΈ by <a href='https://huggingface.co/dnzblgn' target='_blank'>dnzblgn</a></p>
|
86 |
+
"""
|
87 |
+
)
|
88 |
|
89 |
# Run the interface
|
90 |
if __name__ == "__main__":
|
91 |
+
interface.launch()
|