Spaces:
Sleeping
Sleeping
updating app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,47 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
|
|
6 |
def summarize(text):
|
7 |
if not text.strip():
|
8 |
-
return "Please enter a review."
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
|
|
11 |
example_reviews = [
|
12 |
["This product leaks water and smells like burnt plastic."],
|
13 |
["Absolutely loved the screen resolution and battery life."],
|
14 |
["Worst purchase I've made. Do not recommend at all."]
|
15 |
]
|
16 |
|
|
|
17 |
demo = gr.Interface(
|
18 |
fn=summarize,
|
19 |
-
inputs=gr.Textbox(lines=5, placeholder="Enter product review..."),
|
20 |
outputs=gr.Textbox(label="Summary"),
|
|
|
|
|
21 |
examples=example_reviews,
|
22 |
-
|
23 |
-
description="Enter a long product review and get a helpful short summary."
|
24 |
)
|
25 |
|
26 |
-
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Load model with custom generation settings
|
5 |
+
pipe = pipeline(
|
6 |
+
"summarization",
|
7 |
+
model="Manish014/review-summariser-gpt-config1",
|
8 |
+
tokenizer="Manish014/review-summariser-gpt-config1",
|
9 |
+
device=0 # Use GPU if available, else set to -1
|
10 |
+
)
|
11 |
|
12 |
+
# Summarization function with settings
|
13 |
def summarize(text):
|
14 |
if not text.strip():
|
15 |
+
return "Please enter a product review."
|
16 |
+
|
17 |
+
result = pipe(
|
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 |
+
return result[0]["summary_text"]
|
26 |
|
27 |
+
# Example reviews
|
28 |
example_reviews = [
|
29 |
["This product leaks water and smells like burnt plastic."],
|
30 |
["Absolutely loved the screen resolution and battery life."],
|
31 |
["Worst purchase I've made. Do not recommend at all."]
|
32 |
]
|
33 |
|
34 |
+
# Gradio Interface
|
35 |
demo = gr.Interface(
|
36 |
fn=summarize,
|
37 |
+
inputs=gr.Textbox(label="Product Review", lines=5, placeholder="Enter product review..."),
|
38 |
outputs=gr.Textbox(label="Summary"),
|
39 |
+
title="📝 Review Summariser GPT - Config 1",
|
40 |
+
description="Enter a long product review and get a helpful short summary.",
|
41 |
examples=example_reviews,
|
42 |
+
theme="default"
|
|
|
43 |
)
|
44 |
|
45 |
+
# Launch app
|
46 |
+
if __name__ == "__main__":
|
47 |
+
demo.launch()
|