Spaces:
Sleeping
Sleeping
update to timestamp aware version
Browse files
app.py
CHANGED
|
@@ -18,9 +18,8 @@ pipe = pipeline(
|
|
| 18 |
|
| 19 |
print("Model loaded successfully!")
|
| 20 |
|
| 21 |
-
def format_chat_template(document):
|
| 22 |
"""Format input using the recommended template from model card"""
|
| 23 |
-
instruction = "Please summarize the input document."
|
| 24 |
row_json = [{
|
| 25 |
"role": "user",
|
| 26 |
"content": f"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\n{instruction}\n\n### Input:\n{document}\n\n### Response:\n"
|
|
@@ -28,18 +27,18 @@ def format_chat_template(document):
|
|
| 28 |
return tokenizer.apply_chat_template(row_json, tokenize=False, add_generation_prompt=False)
|
| 29 |
|
| 30 |
@spaces.GPU
|
| 31 |
-
def summarize(text):
|
| 32 |
-
"""Generate summary using the model"""
|
| 33 |
try:
|
| 34 |
-
# Format input with
|
| 35 |
-
formatted_input = format_chat_template(text)
|
| 36 |
|
| 37 |
# Generate summary
|
| 38 |
output = pipe(
|
| 39 |
formatted_input,
|
| 40 |
-
max_new_tokens=
|
| 41 |
do_sample=True,
|
| 42 |
-
temperature=0.
|
| 43 |
top_p=0.9,
|
| 44 |
return_full_text=False
|
| 45 |
)
|
|
@@ -54,20 +53,52 @@ def summarize(text):
|
|
| 54 |
# Create Gradio interface
|
| 55 |
demo = gr.Interface(
|
| 56 |
fn=summarize,
|
| 57 |
-
inputs=
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
outputs=gr.Textbox(
|
| 63 |
label="Summary",
|
| 64 |
-
lines=
|
| 65 |
),
|
| 66 |
title="SummLlama3.2-3B Summarization",
|
| 67 |
-
description="Test the DISLab/SummLlama3.2-3B model
|
| 68 |
examples=[
|
| 69 |
-
[
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
)
|
| 72 |
|
| 73 |
if __name__ == "__main__":
|
|
|
|
| 18 |
|
| 19 |
print("Model loaded successfully!")
|
| 20 |
|
| 21 |
+
def format_chat_template(instruction, document):
|
| 22 |
"""Format input using the recommended template from model card"""
|
|
|
|
| 23 |
row_json = [{
|
| 24 |
"role": "user",
|
| 25 |
"content": f"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\n{instruction}\n\n### Input:\n{document}\n\n### Response:\n"
|
|
|
|
| 27 |
return tokenizer.apply_chat_template(row_json, tokenize=False, add_generation_prompt=False)
|
| 28 |
|
| 29 |
@spaces.GPU
|
| 30 |
+
def summarize(instruction, text):
|
| 31 |
+
"""Generate summary using the model with custom instruction"""
|
| 32 |
try:
|
| 33 |
+
# Format input with custom instruction
|
| 34 |
+
formatted_input = format_chat_template(instruction, text)
|
| 35 |
|
| 36 |
# Generate summary
|
| 37 |
output = pipe(
|
| 38 |
formatted_input,
|
| 39 |
+
max_new_tokens=512,
|
| 40 |
do_sample=True,
|
| 41 |
+
temperature=0.7,
|
| 42 |
top_p=0.9,
|
| 43 |
return_full_text=False
|
| 44 |
)
|
|
|
|
| 53 |
# Create Gradio interface
|
| 54 |
demo = gr.Interface(
|
| 55 |
fn=summarize,
|
| 56 |
+
inputs=[
|
| 57 |
+
gr.Textbox(
|
| 58 |
+
lines=3,
|
| 59 |
+
value="Please summarize this meeting transcript, preserving key timestamps and noting when important topics were discussed.",
|
| 60 |
+
label="Custom Instruction",
|
| 61 |
+
placeholder="Enter your instruction here..."
|
| 62 |
+
),
|
| 63 |
+
gr.Textbox(
|
| 64 |
+
lines=10,
|
| 65 |
+
placeholder="Enter text or meeting transcript to summarize...",
|
| 66 |
+
label="Document/Transcript"
|
| 67 |
+
)
|
| 68 |
+
],
|
| 69 |
outputs=gr.Textbox(
|
| 70 |
label="Summary",
|
| 71 |
+
lines=8
|
| 72 |
),
|
| 73 |
title="SummLlama3.2-3B Summarization",
|
| 74 |
+
description="Test the DISLab/SummLlama3.2-3B model with customizable instructions. Modify the instruction to control how the model summarizes your content.",
|
| 75 |
examples=[
|
| 76 |
+
[
|
| 77 |
+
"Please summarize this meeting transcript, preserving key timestamps and noting when important topics were discussed.",
|
| 78 |
+
"""Alvaro Orsi 1:39
|
| 79 |
+
Yeah.
|
| 80 |
+
Mohammad Hossain Dehghan Shoar 1:47
|
| 81 |
+
What that policy does XY and said, what is the impact on each agent and what is the impact on their sick leaves and overall life expectancy? So I think I wanna spend a little bit more time to make it more exciting how agents interact with one another and make it more general in terms of.
|
| 82 |
+
Alvaro Orsi 1:57
|
| 83 |
+
Yeah.
|
| 84 |
+
Yeah.
|
| 85 |
+
Mohammad Hossain Dehghan Shoar 2:07
|
| 86 |
+
Infectious disease as well because at the moment it is set four PM 2.5, but I think it's it's the more difficult to run in versus grad ABM. But I've I think it's it's running, we're getting the same similar results at least."""
|
| 87 |
+
],
|
| 88 |
+
[
|
| 89 |
+
"Summarize the key technical points discussed in this transcript.",
|
| 90 |
+
"""Artificial intelligence has made remarkable progress in recent years, particularly in natural language processing. Large language models can now understand context, generate human-like text, and perform complex reasoning tasks. These advances have enabled applications ranging from chatbots to code generation tools, transforming how we interact with technology."""
|
| 91 |
+
],
|
| 92 |
+
[
|
| 93 |
+
"Extract action items and decisions from this meeting, including who is responsible and any mentioned timeframes.",
|
| 94 |
+
"""Team Meeting - Project Alpha
|
| 95 |
+
John (9:15): We need to finalize the API design by Friday.
|
| 96 |
+
Sarah (9:20): I'll take ownership of the authentication module. Can deliver by Thursday.
|
| 97 |
+
Mike (9:25): The database schema needs review. John, can you look at it by Wednesday?
|
| 98 |
+
John (9:27): Sure, I'll review it tomorrow and get back to you."""
|
| 99 |
+
]
|
| 100 |
+
],
|
| 101 |
+
allow_flagging="never"
|
| 102 |
)
|
| 103 |
|
| 104 |
if __name__ == "__main__":
|