Spaces:
Running
Running
cleanup: remove unused non-streaming summarize_transcript function
Browse files- summarize_transcript.py +0 -37
summarize_transcript.py
CHANGED
|
@@ -32,43 +32,6 @@ def read_transcript(file_path):
|
|
| 32 |
content = f.read()
|
| 33 |
return content
|
| 34 |
|
| 35 |
-
def summarize_transcript(llm, transcript, language='zh-TW'):
|
| 36 |
-
"""Summarize the transcript using the loaded model."""
|
| 37 |
-
# Truncate the transcript to fit within the context window
|
| 38 |
-
# Account for the prompt tokens as well
|
| 39 |
-
max_transcript_length = 1000 # Leave room for prompt and response
|
| 40 |
-
|
| 41 |
-
if len(transcript) > max_transcript_length:
|
| 42 |
-
transcript = transcript[:max_transcript_length]
|
| 43 |
-
print(f"Transcript truncated to {max_transcript_length} characters to fit context window.")
|
| 44 |
-
|
| 45 |
-
# Use the model's chat format based on its template
|
| 46 |
-
if language == 'en':
|
| 47 |
-
messages = [
|
| 48 |
-
{"role": "system", "content": "You are a helpful assistant that summarizes transcripts."},
|
| 49 |
-
{"role": "user", "content": f"Please summarize the following transcript:\n\n{transcript}"}
|
| 50 |
-
]
|
| 51 |
-
else: # Default to zh-TW
|
| 52 |
-
messages = [
|
| 53 |
-
{"role": "system", "content": "你是一個有助的助手,負責總結轉錄內容。"},
|
| 54 |
-
{"role": "user", "content": f"請總結以下內容:\n\n{transcript}"}
|
| 55 |
-
]
|
| 56 |
-
|
| 57 |
-
# Generate the summary using chat completion
|
| 58 |
-
output = llm.create_chat_completion(
|
| 59 |
-
messages=messages,
|
| 60 |
-
max_tokens=512,
|
| 61 |
-
temperature=0.3,
|
| 62 |
-
top_p=0.9,
|
| 63 |
-
repeat_penalty=1.1,
|
| 64 |
-
stop=["<|end_of_text|>", "<|eot_id|>", "<|eom_id|>"]
|
| 65 |
-
)
|
| 66 |
-
|
| 67 |
-
# Reset the model state to ensure clean state for next call
|
| 68 |
-
llm.reset()
|
| 69 |
-
|
| 70 |
-
return output['choices'][0]['message']['content'].strip()
|
| 71 |
-
|
| 72 |
def stream_summarize_transcript(llm, transcript, language='zh-TW'):
|
| 73 |
"""
|
| 74 |
Perform live streaming summary by getting real-time token output from the model.
|
|
|
|
| 32 |
content = f.read()
|
| 33 |
return content
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
def stream_summarize_transcript(llm, transcript, language='zh-TW'):
|
| 36 |
"""
|
| 37 |
Perform live streaming summary by getting real-time token output from the model.
|