jiuuee commited on
Commit
ad88d6b
1 Parent(s): e0c3006

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -5
app.py CHANGED
@@ -113,7 +113,38 @@ def transcribe(audio_filepath, src_lang, tgt_lang, pnc):
113
 
114
  return output_text
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
 
 
117
 
118
 
119
  with gr.Blocks(
@@ -128,15 +159,13 @@ with gr.Blocks(
128
  theme=gr.themes.Default(text_size=gr.themes.sizes.text_lg) # make text slightly bigger (default is text_md )
129
  ) as demo:
130
 
131
- gr.HTML("<h1 style='text-align: center'>NeMo Canary model: Transcribe & Translate audio</h1>")
132
 
133
  with gr.Row():
134
  with gr.Column():
135
  gr.HTML(
136
- "<p><b>Step 1:</b> Upload an audio file or record with your microphone.</p>"
137
-
138
  )
139
-
140
  audio_file = gr.Audio(sources=["microphone"], type="filepath")
141
 
142
 
@@ -151,7 +180,7 @@ with gr.Blocks(
151
  label="Model Output",
152
  elem_id="model_output_text_box",
153
  )
154
-
155
  go_button.click(
156
  fn=transcribe,
157
  inputs = [audio_file],
 
113
 
114
  return output_text
115
 
116
+ import torch
117
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
118
+
119
+ torch.random.manual_seed(0)
120
+
121
+ model = AutoModelForCausalLM.from_pretrained(
122
+ "microsoft/Phi-3-mini-128k-instruct",
123
+ device_map="auto",
124
+ torch_dtype="auto",
125
+ trust_remote_code=True,
126
+ )
127
+ tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-128k-instruct")
128
+
129
+ messages = [
130
+ {"role": "user", "content": str(output_text)},
131
+ ]
132
+
133
+ pipe = pipeline(
134
+ "text-generation",
135
+ model=model,
136
+ tokenizer=tokenizer,
137
+ )
138
+
139
+ generation_args = {
140
+ "max_new_tokens": 500,
141
+ "return_full_text": True,
142
+ "temperature": 0.0,
143
+ "do_sample": False,
144
+ }
145
 
146
+ output_text = pipe(messages, **generation_args)
147
+ print(output[0]['generated_text'])
148
 
149
 
150
  with gr.Blocks(
 
159
  theme=gr.themes.Default(text_size=gr.themes.sizes.text_lg) # make text slightly bigger (default is text_md )
160
  ) as demo:
161
 
162
+ gr.HTML("<h1 style='text-align: center'>Your amazing AI assistant</h1>")
163
 
164
  with gr.Row():
165
  with gr.Column():
166
  gr.HTML(
167
+ "<p><b>Step 1:</b> Record with your microphone.</p>"
 
168
  )
 
169
  audio_file = gr.Audio(sources=["microphone"], type="filepath")
170
 
171
 
 
180
  label="Model Output",
181
  elem_id="model_output_text_box",
182
  )
183
+
184
  go_button.click(
185
  fn=transcribe,
186
  inputs = [audio_file],