Spaces:
Sleeping
Sleeping
new updates
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
summarizer = pipeline(
|
| 6 |
"summarization",
|
| 7 |
model="Manish014/review-summariser-gpt-config1",
|
|
@@ -14,8 +14,8 @@ sentiment_analyzer = pipeline("sentiment-analysis")
|
|
| 14 |
# Inference function
|
| 15 |
def analyze_review(text):
|
| 16 |
if not text.strip():
|
| 17 |
-
return "Please enter a review.", "Sentiment unavailable."
|
| 18 |
-
|
| 19 |
summary = summarizer(
|
| 20 |
text,
|
| 21 |
max_length=80,
|
|
@@ -26,41 +26,50 @@ def analyze_review(text):
|
|
| 26 |
)[0]["summary_text"]
|
| 27 |
|
| 28 |
sentiment = sentiment_analyzer(text)[0]
|
| 29 |
-
|
| 30 |
|
| 31 |
-
return summary,
|
| 32 |
|
| 33 |
-
# Example
|
| 34 |
-
|
| 35 |
["This product leaks water and smells like burnt plastic."],
|
| 36 |
["Absolutely loved the screen resolution and battery life."],
|
| 37 |
-
["Worst purchase I've made. Do not recommend at all."]
|
|
|
|
|
|
|
| 38 |
]
|
| 39 |
|
| 40 |
-
# Build
|
| 41 |
with gr.Blocks(theme=gr.themes.Base()) as demo:
|
| 42 |
gr.Markdown("## π Review Summariser GPT - Config 1")
|
| 43 |
-
gr.Markdown("Enter a
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
with gr.Row():
|
| 46 |
-
|
|
|
|
| 47 |
|
| 48 |
with gr.Row():
|
| 49 |
-
|
| 50 |
-
|
| 51 |
|
| 52 |
-
|
| 53 |
-
clear_btn
|
| 54 |
|
| 55 |
-
|
| 56 |
-
clear_btn.click(lambda: ("", "", ""), outputs=[input_box, summary_output, sentiment_output])
|
| 57 |
|
| 58 |
-
gr.
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
# Run
|
| 65 |
if __name__ == "__main__":
|
| 66 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load models
|
| 5 |
summarizer = pipeline(
|
| 6 |
"summarization",
|
| 7 |
model="Manish014/review-summariser-gpt-config1",
|
|
|
|
| 14 |
# Inference function
|
| 15 |
def analyze_review(text):
|
| 16 |
if not text.strip():
|
| 17 |
+
return "β Please enter a product review.", "β Sentiment unavailable."
|
| 18 |
+
|
| 19 |
summary = summarizer(
|
| 20 |
text,
|
| 21 |
max_length=80,
|
|
|
|
| 26 |
)[0]["summary_text"]
|
| 27 |
|
| 28 |
sentiment = sentiment_analyzer(text)[0]
|
| 29 |
+
sentiment_label = f"{sentiment['label']} ({round(sentiment['score'] * 100, 2)}%)"
|
| 30 |
|
| 31 |
+
return summary, sentiment_label
|
| 32 |
|
| 33 |
+
# Example inputs
|
| 34 |
+
examples = [
|
| 35 |
["This product leaks water and smells like burnt plastic."],
|
| 36 |
["Absolutely loved the screen resolution and battery life."],
|
| 37 |
+
["Worst purchase I've made. Do not recommend at all."],
|
| 38 |
+
["The headphones are okay. Battery is good but fit is not comfortable."],
|
| 39 |
+
["The fan is extremely loud and doesn't cool much."]
|
| 40 |
]
|
| 41 |
|
| 42 |
+
# Build UI
|
| 43 |
with gr.Blocks(theme=gr.themes.Base()) as demo:
|
| 44 |
gr.Markdown("## π Review Summariser GPT - Config 1")
|
| 45 |
+
gr.Markdown("Enter a detailed product review below to receive a helpful summary βοΈ and predicted sentiment π.")
|
| 46 |
+
|
| 47 |
+
with gr.Row():
|
| 48 |
+
review_input = gr.Textbox(label="π£οΈ Product Review", lines=5, placeholder="Write your review here...")
|
| 49 |
|
| 50 |
with gr.Row():
|
| 51 |
+
summary_output = gr.Textbox(label="βοΈ Summary", lines=2)
|
| 52 |
+
sentiment_output = gr.Textbox(label="π Sentiment", lines=1)
|
| 53 |
|
| 54 |
with gr.Row():
|
| 55 |
+
analyze_btn = gr.Button("π Analyze")
|
| 56 |
+
clear_btn = gr.Button("π§Ή Clear")
|
| 57 |
|
| 58 |
+
analyze_btn.click(analyze_review, inputs=review_input, outputs=[summary_output, sentiment_output])
|
| 59 |
+
clear_btn.click(lambda: ("", "", ""), outputs=[review_input, summary_output, sentiment_output])
|
| 60 |
|
| 61 |
+
gr.Examples(examples=examples, inputs=review_input, label="π Try Example Reviews")
|
|
|
|
| 62 |
|
| 63 |
+
with gr.Accordion("βΉοΈ About this App", open=False):
|
| 64 |
+
gr.Markdown(
|
| 65 |
+
"""
|
| 66 |
+
This application uses a fine-tuned T5 model to summarize lengthy product reviews into short summaries and also classifies the sentiment as Positive or Negative.
|
| 67 |
+
- Model: `Manish014/review-summariser-gpt-config1`
|
| 68 |
+
- Summarization by π€ Transformers
|
| 69 |
+
- Sentiment by `distilbert-base-uncased-finetuned-sst-2-english`
|
| 70 |
+
"""
|
| 71 |
+
)
|
| 72 |
|
| 73 |
+
# Run app
|
| 74 |
if __name__ == "__main__":
|
| 75 |
demo.launch()
|