multimodalart HF Staff commited on
Commit
af99ebb
·
verified ·
1 Parent(s): 37cd919

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +12 -7
  2. app.py +140 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,13 +1,18 @@
1
  ---
2
- title: S1 Mini Transcript Cleanup
3
- emoji: 💻
4
- colorFrom: blue
5
- colorTo: pink
6
  sdk: gradio
7
  sdk_version: 6.24.0
8
- python_version: '3.12'
9
  app_file: app.py
10
- pinned: false
 
 
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
1
  ---
2
+ title: S1-mini Transcript Cleanup
3
+ emoji: ✍️
4
+ colorFrom: green
5
+ colorTo: red
6
  sdk: gradio
7
  sdk_version: 6.24.0
 
8
  app_file: app.py
9
+ short_description: Clean and normalize raw ASR transcripts with S1-mini
10
+ python_version: "3.12"
11
+ startup_duration_timeout: 30m
12
  ---
13
 
14
+ ASR transcript cleanup demo using [superwhisper/s1-mini](https://huggingface.co/superwhisper/s1-mini),
15
+ a 0.6B Qwen3-based text normalizer. Paste raw speech-to-text output and get cleaned
16
+ text with proper punctuation, truecasing, filler removal, and formatting.
17
+
18
+ The model is by Superwhisper and is licensed under Apache 2.0 with a naming clause.
app.py ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces # MUST come before torch / transformers
2
+ import torch
3
+ import gradio as gr
4
+
5
+ from transformers import AutoModelForCausalLM, AutoTokenizer
6
+
7
+ MODEL_ID = "superwhisper/s1-mini"
8
+
9
+ SYSTEM_PROMPT = (
10
+ "You are a text normalizer for speech-to-text transcripts. "
11
+ "The input begins with a control line specifying the styling, structure, "
12
+ "and context settings; clean the transcript to match those settings "
13
+ "and output only the cleaned text."
14
+ )
15
+
16
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
17
+ model = AutoModelForCausalLM.from_pretrained(
18
+ MODEL_ID,
19
+ torch_dtype=torch.bfloat16,
20
+ attn_implementation="sdpa",
21
+ ).to("cuda")
22
+ model.eval()
23
+
24
+
25
+ @spaces.GPU(duration=30)
26
+ def clean_transcript(
27
+ transcript: str,
28
+ styling: str = "semi-formal",
29
+ structure: str = "prose",
30
+ context: str = "general",
31
+ ) -> str:
32
+ """Clean and normalize a raw ASR transcript.
33
+
34
+ Applies punctuation, truecasing, filler removal, and formatting based on
35
+ the selected styling, structure, and context settings.
36
+
37
+ Args:
38
+ transcript: Raw ASR transcript text (disfluent, unpunctuated).
39
+ styling: Register / formality level (casual, semi-casual, semi-formal, formal).
40
+ structure: Output structure (prose or lists).
41
+ context: Context mode (general or email).
42
+
43
+ Returns:
44
+ Cleaned, normalized transcript as plain text.
45
+ """
46
+ control = f"[Styling: {styling}] [Structure: {structure}] [Context: {context}]"
47
+ messages = [
48
+ {"role": "system", "content": SYSTEM_PROMPT},
49
+ {"role": "user", "content": f"{control}\n{transcript}"},
50
+ ]
51
+ text = tokenizer.apply_chat_template(
52
+ messages,
53
+ tokenize=False,
54
+ add_generation_prompt=True,
55
+ enable_thinking=False,
56
+ )
57
+ inputs = tokenizer(text, return_tensors="pt").to(model.device)
58
+ input_len = inputs.input_ids.shape[1]
59
+ max_new = min(1024, int(input_len * 1.3) + 32)
60
+ with torch.no_grad():
61
+ out = model.generate(
62
+ **inputs,
63
+ max_new_tokens=max_new,
64
+ do_sample=False,
65
+ )
66
+ generated = out[0][input_len:]
67
+ result = tokenizer.decode(generated, skip_special_tokens=True).strip()
68
+ return result
69
+
70
+
71
+ CSS = """
72
+ #col-container { max-width: 900px; margin: 0 auto; }
73
+ .dark .gradio-container { color: var(--body-text-color); }
74
+ """
75
+
76
+ with gr.Blocks(theme=gr.themes.Citrus(), css=CSS) as demo:
77
+ gr.Markdown(
78
+ "# S1-mini · ASR Transcript Cleanup\n"
79
+ "A 0.6B Qwen3-based model that cleans raw speech-to-text transcripts: "
80
+ "removes fillers, resolves self-corrections, adds punctuation and truecasing, "
81
+ "and formats numbers/dates/emails — all controlled by styling and structure settings.\n\n"
82
+ "Model: [superwhisper/s1-mini](https://huggingface.co/superwhisper/s1-mini)"
83
+ )
84
+
85
+ with gr.Column(elem_id="col-container"):
86
+ with gr.Row():
87
+ transcript_input = gr.Textbox(
88
+ label="Raw ASR Transcript",
89
+ placeholder="Paste raw, unpunctuated speech-to-text output here…",
90
+ lines=6,
91
+ scale=4,
92
+ )
93
+ with gr.Row():
94
+ styling = gr.Dropdown(
95
+ choices=["casual", "semi-casual", "semi-formal", "formal"],
96
+ value="semi-formal",
97
+ label="Styling",
98
+ scale=1,
99
+ )
100
+ structure = gr.Dropdown(
101
+ choices=["prose", "lists"],
102
+ value="prose",
103
+ label="Structure",
104
+ scale=1,
105
+ )
106
+ context = gr.Dropdown(
107
+ choices=["general", "email"],
108
+ value="general",
109
+ label="Context",
110
+ scale=1,
111
+ )
112
+ run_btn = gr.Button("Clean Transcript", variant="primary")
113
+ output = gr.Textbox(
114
+ label="Cleaned Transcript",
115
+ lines=6,
116
+ show_copy_button=True,
117
+ )
118
+
119
+ run_btn.click(
120
+ fn=clean_transcript,
121
+ inputs=[transcript_input, styling, structure, context],
122
+ outputs=output,
123
+ api_name="clean",
124
+ )
125
+
126
+ gr.Examples(
127
+ examples=[
128
+ ["so um i need to like send the the report by uh friday no wait make that thursday"],
129
+ ["hey can you like um check the the numbers for q3 and also um make sure the the spreadsheet is up to date"],
130
+ ["hi john um i was wondering if you could um send me the the quarterly report by end of day friday thanks"],
131
+ ["so the meeting is at um three pm on tuesday and we need to like bring the the slides and also the budget numbers"],
132
+ ],
133
+ inputs=transcript_input,
134
+ outputs=output,
135
+ fn=clean_transcript,
136
+ cache_examples=True,
137
+ cache_mode="lazy",
138
+ )
139
+
140
+ demo.launch(mcp_server=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers>=4.51.0
2
+ torch
3
+ accelerate