Spaces:
Sleeping
Sleeping
updated app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,34 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Load
|
5 |
-
|
6 |
"summarization",
|
7 |
model="Manish014/review-summariser-gpt-config1",
|
8 |
tokenizer="Manish014/review-summariser-gpt-config1",
|
9 |
-
device=0 # Use GPU if available
|
10 |
)
|
11 |
|
12 |
-
|
13 |
-
|
|
|
|
|
14 |
if not text.strip():
|
15 |
-
return "Please enter a
|
16 |
-
|
17 |
-
|
18 |
text,
|
19 |
max_length=80,
|
20 |
min_length=10,
|
21 |
num_beams=4,
|
22 |
early_stopping=True,
|
23 |
length_penalty=1.2
|
24 |
-
)
|
25 |
-
|
|
|
|
|
|
|
|
|
26 |
|
27 |
# Example reviews
|
28 |
example_reviews = [
|
@@ -31,17 +37,30 @@ example_reviews = [
|
|
31 |
["Worst purchase I've made. Do not recommend at all."]
|
32 |
]
|
33 |
|
34 |
-
# Gradio
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
-
#
|
46 |
if __name__ == "__main__":
|
47 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Load both summarization and sentiment models
|
5 |
+
summarizer = pipeline(
|
6 |
"summarization",
|
7 |
model="Manish014/review-summariser-gpt-config1",
|
8 |
tokenizer="Manish014/review-summariser-gpt-config1",
|
9 |
+
device=0 # Use GPU if available
|
10 |
)
|
11 |
|
12 |
+
sentiment_analyzer = pipeline("sentiment-analysis")
|
13 |
+
|
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,
|
22 |
min_length=10,
|
23 |
num_beams=4,
|
24 |
early_stopping=True,
|
25 |
length_penalty=1.2
|
26 |
+
)[0]["summary_text"]
|
27 |
+
|
28 |
+
sentiment = sentiment_analyzer(text)[0]
|
29 |
+
sentiment_output = f"{sentiment['label']} ({round(sentiment['score'] * 100, 2)}%)"
|
30 |
+
|
31 |
+
return summary, sentiment_output
|
32 |
|
33 |
# Example reviews
|
34 |
example_reviews = [
|
|
|
37 |
["Worst purchase I've made. Do not recommend at all."]
|
38 |
]
|
39 |
|
40 |
+
# Build Gradio UI
|
41 |
+
with gr.Blocks(theme=gr.themes.Base()) as demo:
|
42 |
+
gr.Markdown("## π Review Summariser GPT - Config 1")
|
43 |
+
gr.Markdown("Enter a long product review below to get a helpful short summary and sentiment prediction.")
|
44 |
+
|
45 |
+
with gr.Row():
|
46 |
+
input_box = gr.Textbox(label="π£οΈ Product Review", lines=5, placeholder="Write your detailed review here...")
|
47 |
+
|
48 |
+
with gr.Row():
|
49 |
+
summary_output = gr.Textbox(label="βοΈ Summary")
|
50 |
+
sentiment_output = gr.Textbox(label="π Sentiment")
|
51 |
+
|
52 |
+
submit_btn = gr.Button("π Analyze Review")
|
53 |
+
clear_btn = gr.Button("π§Ή Clear")
|
54 |
+
|
55 |
+
submit_btn.click(analyze_review, inputs=input_box, outputs=[summary_output, sentiment_output])
|
56 |
+
clear_btn.click(lambda: ("", "", ""), outputs=[input_box, summary_output, sentiment_output])
|
57 |
+
|
58 |
+
gr.Examples(
|
59 |
+
examples=example_reviews,
|
60 |
+
inputs=input_box,
|
61 |
+
label="π Try an Example"
|
62 |
+
)
|
63 |
|
64 |
+
# Run the app
|
65 |
if __name__ == "__main__":
|
66 |
demo.launch()
|