Update app.py
Browse files
app.py
CHANGED
@@ -5,20 +5,21 @@ import pandas as pd
|
|
5 |
from fpdf import FPDF
|
6 |
from datetime import datetime
|
7 |
|
8 |
-
# 🎯 مدل عمومی
|
9 |
summarizer = pipeline(
|
10 |
"text2text-generation",
|
11 |
-
model="
|
12 |
)
|
13 |
|
14 |
-
#
|
15 |
def summarize_text(text):
|
16 |
if not text.strip():
|
17 |
return "⚠️ لطفاً متن وارد کنید."
|
18 |
-
|
|
|
19 |
return result[0]["generated_text"]
|
20 |
|
21 |
-
#
|
22 |
def summarize_pdf(file_path):
|
23 |
try:
|
24 |
reader = PyPDF2.PdfReader(file_path)
|
@@ -48,7 +49,7 @@ def save_to_excel(text, summary):
|
|
48 |
df.to_excel(filename, index=False)
|
49 |
return filename
|
50 |
|
51 |
-
#
|
52 |
with gr.Blocks(css="""
|
53 |
body { font-family: Vazir, sans-serif; background: #f9fafb; }
|
54 |
h1 { font-weight: bold; color: white; text-align: center; padding: 20px;
|
@@ -58,7 +59,7 @@ with gr.Blocks(css="""
|
|
58 |
button { border-radius: 8px !important; font-weight: bold; }
|
59 |
""") as demo:
|
60 |
|
61 |
-
gr.Markdown("<h1>📝 SummarizeX — خلاصهساز متن و PDF (
|
62 |
|
63 |
with gr.Tab("خلاصه متن"):
|
64 |
text_input = gr.Textbox(lines=10, placeholder="متن خود را اینجا وارد کنید...")
|
|
|
5 |
from fpdf import FPDF
|
6 |
from datetime import datetime
|
7 |
|
8 |
+
# 🎯 مدل عمومی mT5 کوچک (بدون نیاز به توکن)
|
9 |
summarizer = pipeline(
|
10 |
"text2text-generation",
|
11 |
+
model="google/mt5-small"
|
12 |
)
|
13 |
|
14 |
+
# خلاصهسازی متن
|
15 |
def summarize_text(text):
|
16 |
if not text.strip():
|
17 |
return "⚠️ لطفاً متن وارد کنید."
|
18 |
+
prompt = f"لطفاً این متن را به صورت خلاصه بیان کن:\n{text}"
|
19 |
+
result = summarizer(prompt, max_length=150, min_length=30, do_sample=False)
|
20 |
return result[0]["generated_text"]
|
21 |
|
22 |
+
# خلاصهسازی PDF
|
23 |
def summarize_pdf(file_path):
|
24 |
try:
|
25 |
reader = PyPDF2.PdfReader(file_path)
|
|
|
49 |
df.to_excel(filename, index=False)
|
50 |
return filename
|
51 |
|
52 |
+
# رابط کاربری
|
53 |
with gr.Blocks(css="""
|
54 |
body { font-family: Vazir, sans-serif; background: #f9fafb; }
|
55 |
h1 { font-weight: bold; color: white; text-align: center; padding: 20px;
|
|
|
59 |
button { border-radius: 8px !important; font-weight: bold; }
|
60 |
""") as demo:
|
61 |
|
62 |
+
gr.Markdown("<h1>📝 SummarizeX — خلاصهساز متن و PDF (بدون نیاز به توکن)</h1>")
|
63 |
|
64 |
with gr.Tab("خلاصه متن"):
|
65 |
text_input = gr.Textbox(lines=10, placeholder="متن خود را اینجا وارد کنید...")
|