Spaces:
Sleeping
Sleeping
File size: 2,727 Bytes
3bb0195 8d5c044 ff7a6a8 5b67120 3bb0195 63c0d9a c3564f5 3bb0195 c3564f5 3bb0195 ff7a6a8 8d5c044 63c0d9a ff7a6a8 63c0d9a 3bb0195 13bb12c 3bb0195 13bb12c 3bb0195 ff7a6a8 63c0d9a c3564f5 63c0d9a 3bb0195 63c0d9a 3bb0195 ff7a6a8 c3564f5 3bb0195 91a5265 63c0d9a ff7a6a8 8bbf9e2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
import gradio as gr
from transformers import pipeline, AutoTokenizer
import torch
import spaces
#model_name = "DISLab/SummLlama3.2-3B"
model_name = "DISLab/SummLlama3.1-8B"
print(f"Loading model: {model_name}")
tokenizer = AutoTokenizer.from_pretrained(model_name)
pipe = pipeline(
"text-generation",
model=model_name,
tokenizer=tokenizer,
device_map="auto",
torch_dtype=torch.float16
)
print("Model loaded successfully!")
def format_chat_template(instruction, document):
enhanced_instruction = f"{instruction} If the input contains timestamps, preserve them and note when key topics were discussed."
row_json = [{
"role": "user",
"content": f"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\n{enhanced_instruction}\n\n### Input:\n{document}\n\n### Response:\n"
}]
return tokenizer.apply_chat_template(row_json, tokenize=False, add_generation_prompt=False)
@spaces.GPU
def summarize(instruction, text):
try:
formatted_input = format_chat_template(instruction, text)
output = pipe(
formatted_input,
max_new_tokens=3000,
do_sample=True,
temperature=0.7,
top_p=0.9,
return_full_text=False
)
summary = output[0]['generated_text'].strip()
return summary
except Exception as e:
return f"Error: {str(e)}"
demo = gr.Interface(
fn=summarize,
inputs=[
gr.Textbox(
lines=3,
value="Please provide a concise summary of this meeting transcript.",
label="Custom Instruction",
placeholder="Enter your instruction here..."
),
gr.Textbox(
lines=10,
placeholder="Enter text or meeting transcript to summarize...",
label="Document/Transcript"
)
],
outputs=gr.Textbox(
label="Summary",
lines=8
),
title="SummLlama3.2-3B Summarization",
description="Test the DISLab/SummLlama3.2-3B model with customizable instructions. Timestamps are automatically preserved when present in the input.",
examples=[
["Please provide a concise summary of this meeting transcript."],
["Summarize the key technical points discussed."],
["Extract action items and decisions, including who is responsible."],
["Provide a brief summary highlighting main topics."],
["Focus on technical details and implementation discussions."],
["Create a bullet-point summary of key takeaways."]
],
allow_flagging="never"
)
if __name__ == "__main__":
demo.launch() |