Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,11 @@ from collections import Counter
|
|
8 |
import re
|
9 |
import os
|
10 |
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
MODEL_PATH = "hideosnes/Bart-T2T-Distill_GildaBot"
|
13 |
|
@@ -35,8 +40,11 @@ def summarize(file, text, style, length):
|
|
35 |
# Fallback if fitz can't read the file
|
36 |
text_input = "Error: Could not read PDF file"
|
37 |
elif file.name.endswith(".txt"):
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
40 |
elif text:
|
41 |
text_input = text
|
42 |
# If the input text is empty or contains only whitespace,
|
@@ -45,7 +53,7 @@ def summarize(file, text, style, length):
|
|
45 |
# Gradio expects the summarize() function to always return the same number of outputs,
|
46 |
# so we return a message for the first output (the summary box) and None for the rest.
|
47 |
# This ensures the UI remains consistent and doesn't break if the input is empty.
|
48 |
-
return "Maybe try uploading a file or typing some text?", None, None, None, None, None
|
49 |
|
50 |
# Language detection
|
51 |
try:
|
@@ -127,7 +135,7 @@ def summarize(file, text, style, length):
|
|
127 |
|
128 |
return summary, ", ".join(keywords), original_len, summary_len, f"{reduction:.2f}%", fig
|
129 |
|
130 |
-
with gr.Blocks() as demo:
|
131 |
gr.Markdown("Summarizer (T2T)")
|
132 |
|
133 |
with gr.Row(): #left column
|
@@ -138,7 +146,7 @@ with gr.Blocks() as demo:
|
|
138 |
with gr.Row(): # for inline horizontal layout
|
139 |
style = gr.Dropdown(["Precise", "Sloppy", "Keywords"], label="Style")
|
140 |
length = gr.Dropdown(["Short", "Middle", "Long"], label="Length")
|
141 |
-
token_info = gr.Text(
|
142 |
btn = gr.Button("Transform")
|
143 |
|
144 |
with gr.Column(): #right column
|
@@ -155,4 +163,10 @@ with gr.Blocks() as demo:
|
|
155 |
outputs=[summary, keywords, original_len, summary_len, reduction, plot]
|
156 |
)
|
157 |
|
158 |
-
demo.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
import re
|
9 |
import os
|
10 |
|
11 |
+
theme = gr.themes.Ocean(
|
12 |
+
primary_hue="sky",
|
13 |
+
secondary_hue="indigo",
|
14 |
+
neutral_hue="neutral",
|
15 |
+
)
|
16 |
|
17 |
MODEL_PATH = "hideosnes/Bart-T2T-Distill_GildaBot"
|
18 |
|
|
|
40 |
# Fallback if fitz can't read the file
|
41 |
text_input = "Error: Could not read PDF file"
|
42 |
elif file.name.endswith(".txt"):
|
43 |
+
try:
|
44 |
+
with open(file.name, 'r', encoding='utf-8') as f:
|
45 |
+
text_input = f.read()
|
46 |
+
except:
|
47 |
+
text_input = str(file)
|
48 |
elif text:
|
49 |
text_input = text
|
50 |
# If the input text is empty or contains only whitespace,
|
|
|
53 |
# Gradio expects the summarize() function to always return the same number of outputs,
|
54 |
# so we return a message for the first output (the summary box) and None for the rest.
|
55 |
# This ensures the UI remains consistent and doesn't break if the input is empty.
|
56 |
+
return "Maybe try uploading a file or typing some proper text?", None, None, None, None, None
|
57 |
|
58 |
# Language detection
|
59 |
try:
|
|
|
135 |
|
136 |
return summary, ", ".join(keywords), original_len, summary_len, f"{reduction:.2f}%", fig
|
137 |
|
138 |
+
with gr.Blocks(theme=theme) as demo:
|
139 |
gr.Markdown("Summarizer (T2T)")
|
140 |
|
141 |
with gr.Row(): #left column
|
|
|
146 |
with gr.Row(): # for inline horizontal layout
|
147 |
style = gr.Dropdown(["Precise", "Sloppy", "Keywords"], label="Style")
|
148 |
length = gr.Dropdown(["Short", "Middle", "Long"], label="Length")
|
149 |
+
token_info = gr.Text("1024 tokens ~ 750–800 words")
|
150 |
btn = gr.Button("Transform")
|
151 |
|
152 |
with gr.Column(): #right column
|
|
|
163 |
outputs=[summary, keywords, original_len, summary_len, reduction, plot]
|
164 |
)
|
165 |
|
166 |
+
demo.launch(share=True)
|
167 |
+
|
168 |
+
# issues:
|
169 |
+
# text feld +ber transform button, ?
|
170 |
+
# txt dateien selbes problem, wie bei pdf - name vom file und prompt, statt inhalt ?
|
171 |
+
# neues gradio theme !
|
172 |
+
# pypi für exakte versionsnummererung "version pinning" in requirements.txt
|