Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,6 @@ from transformers import pipeline, AutoTokenizer
|
|
| 3 |
import torch
|
| 4 |
import spaces
|
| 5 |
|
| 6 |
-
# Load model and tokenizer globally
|
| 7 |
model_name = "DISLab/SummLlama3.2-3B"
|
| 8 |
print(f"Loading model: {model_name}")
|
| 9 |
|
|
@@ -19,8 +18,6 @@ pipe = pipeline(
|
|
| 19 |
print("Model loaded successfully!")
|
| 20 |
|
| 21 |
def format_chat_template(instruction, document):
|
| 22 |
-
"""Format input using the recommended template with timestamp awareness built-in"""
|
| 23 |
-
# Enhanced instruction that always includes timestamp awareness
|
| 24 |
enhanced_instruction = f"{instruction} If the input contains timestamps, preserve them and note when key topics were discussed."
|
| 25 |
|
| 26 |
row_json = [{
|
|
@@ -31,12 +28,9 @@ def format_chat_template(instruction, document):
|
|
| 31 |
|
| 32 |
@spaces.GPU
|
| 33 |
def summarize(instruction, text):
|
| 34 |
-
"""Generate summary using the model with custom instruction"""
|
| 35 |
try:
|
| 36 |
-
# Format input with enhanced instruction
|
| 37 |
formatted_input = format_chat_template(instruction, text)
|
| 38 |
|
| 39 |
-
# Generate summary
|
| 40 |
output = pipe(
|
| 41 |
formatted_input,
|
| 42 |
max_new_tokens=512,
|
|
@@ -46,14 +40,12 @@ def summarize(instruction, text):
|
|
| 46 |
return_full_text=False
|
| 47 |
)
|
| 48 |
|
| 49 |
-
# Extract the generated summary
|
| 50 |
summary = output[0]['generated_text'].strip()
|
| 51 |
return summary
|
| 52 |
|
| 53 |
except Exception as e:
|
| 54 |
return f"Error: {str(e)}"
|
| 55 |
|
| 56 |
-
# Create Gradio interface
|
| 57 |
demo = gr.Interface(
|
| 58 |
fn=summarize,
|
| 59 |
inputs=[
|
|
@@ -105,34 +97,4 @@ John (9:27): Sure, I'll review it tomorrow and get back to you."""
|
|
| 105 |
)
|
| 106 |
|
| 107 |
if __name__ == "__main__":
|
| 108 |
-
demo.launch()
|
| 109 |
-
```
|
| 110 |
-
|
| 111 |
-
## Key Changes:
|
| 112 |
-
|
| 113 |
-
**What's different:**
|
| 114 |
-
1. The `format_chat_template` function now automatically appends: `"If the input contains timestamps, preserve them and note when key topics were discussed."` to ANY instruction
|
| 115 |
-
2. Default instruction is now simpler: `"Please provide a concise summary of this meeting transcript."`
|
| 116 |
-
3. Users don't need to mention timestamps anymore
|
| 117 |
-
|
| 118 |
-
**Now you can use simple instructions like:**
|
| 119 |
-
- "Provide a concise summary"
|
| 120 |
-
- "Extract action items"
|
| 121 |
-
- "Summarize technical discussions"
|
| 122 |
-
- "Focus on decisions made"
|
| 123 |
-
|
| 124 |
-
**The system will automatically:**
|
| 125 |
-
- ✅ Preserve timestamps when present
|
| 126 |
-
- ✅ Note when topics were discussed
|
| 127 |
-
- ✅ Keep chronological flow
|
| 128 |
-
|
| 129 |
-
**For OpenWebUI, the equivalent system prompt would be:**
|
| 130 |
-
```
|
| 131 |
-
You are a summarization assistant. Always follow these rules:
|
| 132 |
-
|
| 133 |
-
1. If the input contains timestamps, preserve them and note when key topics were discussed
|
| 134 |
-
2. Identify speakers and their contributions
|
| 135 |
-
3. Maintain chronological order
|
| 136 |
-
4. Follow the user's specific instruction for the summary style
|
| 137 |
-
|
| 138 |
-
The user will provide their custom instruction followed by the document/transcript.
|
|
|
|
| 3 |
import torch
|
| 4 |
import spaces
|
| 5 |
|
|
|
|
| 6 |
model_name = "DISLab/SummLlama3.2-3B"
|
| 7 |
print(f"Loading model: {model_name}")
|
| 8 |
|
|
|
|
| 18 |
print("Model loaded successfully!")
|
| 19 |
|
| 20 |
def format_chat_template(instruction, document):
|
|
|
|
|
|
|
| 21 |
enhanced_instruction = f"{instruction} If the input contains timestamps, preserve them and note when key topics were discussed."
|
| 22 |
|
| 23 |
row_json = [{
|
|
|
|
| 28 |
|
| 29 |
@spaces.GPU
|
| 30 |
def summarize(instruction, text):
|
|
|
|
| 31 |
try:
|
|
|
|
| 32 |
formatted_input = format_chat_template(instruction, text)
|
| 33 |
|
|
|
|
| 34 |
output = pipe(
|
| 35 |
formatted_input,
|
| 36 |
max_new_tokens=512,
|
|
|
|
| 40 |
return_full_text=False
|
| 41 |
)
|
| 42 |
|
|
|
|
| 43 |
summary = output[0]['generated_text'].strip()
|
| 44 |
return summary
|
| 45 |
|
| 46 |
except Exception as e:
|
| 47 |
return f"Error: {str(e)}"
|
| 48 |
|
|
|
|
| 49 |
demo = gr.Interface(
|
| 50 |
fn=summarize,
|
| 51 |
inputs=[
|
|
|
|
| 97 |
)
|
| 98 |
|
| 99 |
if __name__ == "__main__":
|
| 100 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|