yasamankm commited on
Commit
fb6dc25
·
verified ·
1 Parent(s): 7e73e8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -37
app.py CHANGED
@@ -5,23 +5,20 @@ import pandas as pd
5
  from fpdf import FPDF
6
  from datetime import datetime
7
 
8
- # رنگ‌های برند
9
- PRIMARY_GRADIENT = "linear-gradient(90deg, #6a4cff, #00c9b7)"
10
- HEADER_COLOR = "#1f2937"
11
- TEXT_COLOR = "#111827"
12
-
13
- # مدل خلاصه‌سازی
14
  summarizer = pipeline(
15
- "summarization",
16
- model="m3hrdadfi/mt5-small-parsinlu-summarization-fa"
 
17
  )
18
 
19
- # --- توابع ---
20
  def summarize_text(text):
21
  if not text.strip():
22
  return "⚠️ لطفاً متن وارد کنید."
23
- result = summarizer(text, max_length=150, min_length=30)
24
- return result[0]["summary_text"]
 
25
 
26
  def summarize_pdf(file):
27
  try:
@@ -50,7 +47,6 @@ def save_to_excel(text, summary):
50
  df.to_excel(filename, index=False)
51
  return filename
52
 
53
- # --- رابط کاربری ---
54
  with gr.Blocks(css="""
55
  body { font-family: Vazir, sans-serif; background: #f9fafb; }
56
  h1 { font-weight: bold; color: white; text-align: center; padding: 20px;
@@ -61,37 +57,31 @@ with gr.Blocks(css="""
61
  """) as demo:
62
 
63
  with gr.Row():
64
- gr.Markdown("<h1>📝 SummarizeX — خلاصه‌ساز متن و PDF</h1>")
65
 
66
- with gr.Tab("خلاصه متن") as tab1:
67
- with gr.Row(elem_classes="tab"):
68
- text_input = gr.Textbox(lines=10, placeholder="متن خود را اینجا وارد کنید...")
69
- summary_output = gr.Textbox(lines=8, label="خلاصه متن")
70
- with gr.Row():
71
- btn_summary = gr.Button(" خلاصه کن", elem_id="btn-summary")
72
- with gr.Row():
73
- pdf_btn = gr.Button("📄 ذخیره به PDF")
74
- excel_btn = gr.Button("📊 ذخیره به Excel")
75
- with gr.Row():
76
- file_pdf_out = gr.File(label="دانلود PDF")
77
- file_excel_out = gr.File(label="دانلود Excel")
78
 
79
  btn_summary.click(summarize_text, inputs=text_input, outputs=summary_output)
80
  pdf_btn.click(lambda t, s: save_to_pdf(t, s), inputs=[text_input, summary_output], outputs=file_pdf_out)
81
  excel_btn.click(lambda t, s: save_to_excel(t, s), inputs=[text_input, summary_output], outputs=file_excel_out)
82
 
83
- with gr.Tab("خلاصه PDF") as tab2:
84
- with gr.Row(elem_classes="tab"):
85
- pdf_input = gr.File(type="file", file_types=[".pdf"], label="انتخاب فایل PDF")
86
- pdf_summary_output = gr.Textbox(lines=8, label="خلاصه PDF")
87
- with gr.Row():
88
- btn_pdf_summary = gr.Button(" خلاصه PDF")
89
- with gr.Row():
90
- pdf_btn2 = gr.Button("📄 ذخیره به PDF")
91
- excel_btn2 = gr.Button("📊 ذخیره به Excel")
92
- with gr.Row():
93
- file_pdf_out2 = gr.File(label="دانلود PDF")
94
- file_excel_out2 = gr.File(label="دانلود Excel")
95
 
96
  btn_pdf_summary.click(summarize_pdf, inputs=pdf_input, outputs=pdf_summary_output)
97
  pdf_btn2.click(lambda f, s: save_to_pdf("PDF File", s), inputs=[pdf_input, pdf_summary_output], outputs=file_pdf_out2)
 
5
  from fpdf import FPDF
6
  from datetime import datetime
7
 
8
+ # 🎯 مدل عمومی و رایگان برای خلاصه‌سازی فارسی
9
+ # با استفاده از mt5-small و prompt فارسی
 
 
 
 
10
  summarizer = pipeline(
11
+ "text2text-generation",
12
+ model="google/mt5-small",
13
+ tokenizer="google/mt5-small"
14
  )
15
 
 
16
  def summarize_text(text):
17
  if not text.strip():
18
  return "⚠️ لطفاً متن وارد کنید."
19
+ prompt = f"لطفاً این متن را به صورت خلاصه بیان کن:\n{text}"
20
+ result = summarizer(prompt, max_length=150, min_length=30, do_sample=False)
21
+ return result[0]["generated_text"]
22
 
23
  def summarize_pdf(file):
24
  try:
 
47
  df.to_excel(filename, index=False)
48
  return filename
49
 
 
50
  with gr.Blocks(css="""
51
  body { font-family: Vazir, sans-serif; background: #f9fafb; }
52
  h1 { font-weight: bold; color: white; text-align: center; padding: 20px;
 
57
  """) as demo:
58
 
59
  with gr.Row():
60
+ gr.Markdown("<h1>📝 SummarizeX — خلاصه‌ساز متن و PDF (نسخه عمومی)</h1>")
61
 
62
+ with gr.Tab("خلاصه متن"):
63
+ text_input = gr.Textbox(lines=10, placeholder="متن خود را اینجا وارد کنید...")
64
+ summary_output = gr.Textbox(lines=8, label="خلاصه متن")
65
+ btn_summary = gr.Button("✨ خلاصه کن")
66
+
67
+ pdf_btn = gr.Button("📄 ذخیره به PDF")
68
+ excel_btn = gr.Button("📊 ذخیره به Excel")
69
+ file_pdf_out = gr.File(label="دانلود PDF")
70
+ file_excel_out = gr.File(label="دانلود Excel")
 
 
 
71
 
72
  btn_summary.click(summarize_text, inputs=text_input, outputs=summary_output)
73
  pdf_btn.click(lambda t, s: save_to_pdf(t, s), inputs=[text_input, summary_output], outputs=file_pdf_out)
74
  excel_btn.click(lambda t, s: save_to_excel(t, s), inputs=[text_input, summary_output], outputs=file_excel_out)
75
 
76
+ with gr.Tab("خلاصه PDF"):
77
+ pdf_input = gr.File(type="file", file_types=[".pdf"])
78
+ pdf_summary_output = gr.Textbox(lines=8, label="خلاصه PDF")
79
+ btn_pdf_summary = gr.Button("✨ خلاصه PDF")
80
+
81
+ pdf_btn2 = gr.Button("📄 ذخیره به PDF")
82
+ excel_btn2 = gr.Button("📊 ذخیره به Excel")
83
+ file_pdf_out2 = gr.File(label="دانلود PDF")
84
+ file_excel_out2 = gr.File(label="دانلود Excel")
 
 
 
85
 
86
  btn_pdf_summary.click(summarize_pdf, inputs=pdf_input, outputs=pdf_summary_output)
87
  pdf_btn2.click(lambda f, s: save_to_pdf("PDF File", s), inputs=[pdf_input, pdf_summary_output], outputs=file_pdf_out2)