Spaces:
Running
Running
Update app.py
Browse filesno more prompt in the summary
app.py
CHANGED
|
@@ -63,9 +63,9 @@ def summarize(file, text, style, length):
|
|
| 63 |
# System prompt based on language and style
|
| 64 |
prompt_map = {
|
| 65 |
"en": {
|
| 66 |
-
"Precise": "
|
| 67 |
-
"Sloppy": "
|
| 68 |
-
"Keywords": "
|
| 69 |
}#, <-- don't forget the comma!!!!!
|
| 70 |
#"foo": { "precise": "another language or prompt map could go here"}
|
| 71 |
}
|
|
@@ -96,6 +96,12 @@ def summarize(file, text, style, length):
|
|
| 96 |
no_repeat_ngram_size=3
|
| 97 |
)
|
| 98 |
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
# These lines calculate and store the word count of the original text,
|
| 101 |
# the word count of the summary, and the percentage reduction in length after summarization.
|
|
@@ -131,7 +137,7 @@ with gr.Blocks() as demo:
|
|
| 131 |
|
| 132 |
with gr.Row(): # for inline horizontal layout
|
| 133 |
style = gr.Dropdown(["Precise", "Sloppy", "Keywords"], label="Style")
|
| 134 |
-
length = gr.
|
| 135 |
token_info = gr.Text(label="Max. Tokens:", value="1024 tokens ~ 750–800 words", interactive=False)
|
| 136 |
btn = gr.Button("Transform")
|
| 137 |
|
|
@@ -149,4 +155,4 @@ with gr.Blocks() as demo:
|
|
| 149 |
outputs=[summary, keywords, original_len, summary_len, reduction, plot]
|
| 150 |
)
|
| 151 |
|
| 152 |
-
demo.launch()
|
|
|
|
| 63 |
# System prompt based on language and style
|
| 64 |
prompt_map = {
|
| 65 |
"en": {
|
| 66 |
+
"Precise": "Summarize concisely in a dry, scientific and academic style:",
|
| 67 |
+
"Sloppy": "Summarize comprehensively for a child:",
|
| 68 |
+
"Keywords": "Write only a list of important keywords of main ideas separated by a comma:",
|
| 69 |
}#, <-- don't forget the comma!!!!!
|
| 70 |
#"foo": { "precise": "another language or prompt map could go here"}
|
| 71 |
}
|
|
|
|
| 96 |
no_repeat_ngram_size=3
|
| 97 |
)
|
| 98 |
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 99 |
+
# removing the prompt text from the summary
|
| 100 |
+
prompt_text = prompt_map.get(lang_code, prompt_map["en"])[style]
|
| 101 |
+
if summary.startswith(prompt_text):
|
| 102 |
+
summary = summary[len(prompt_text):].strip()
|
| 103 |
+
if text_input in summary:
|
| 104 |
+
summary = summary.replace(text_input, "").strip()
|
| 105 |
|
| 106 |
# These lines calculate and store the word count of the original text,
|
| 107 |
# the word count of the summary, and the percentage reduction in length after summarization.
|
|
|
|
| 137 |
|
| 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(label="Max. Tokens:", value="1024 tokens ~ 750–800 words", interactive=False)
|
| 142 |
btn = gr.Button("Transform")
|
| 143 |
|
|
|
|
| 155 |
outputs=[summary, keywords, original_len, summary_len, reduction, plot]
|
| 156 |
)
|
| 157 |
|
| 158 |
+
demo.launch(share=True)
|