MarcosAcv commited on
Commit
943b118
·
1 Parent(s): 56e16a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -9
app.py CHANGED
@@ -1,13 +1,35 @@
1
- import streamlit as st
2
- from transformers import pipeline
 
3
 
4
- print('I am alive!')
5
 
6
- def image2text(url):
7
- image_to_text_pipe = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
8
- text = image_to_text_pipe(url)[0]['generated_text']
9
 
10
- print(text)
11
- return text
12
 
13
- image2text(Capture.PNG)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
3
+ from datasets import load_dataset
4
 
 
5
 
6
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
7
+ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
 
8
 
9
+ model_id = "openai/whisper-large-v3"
 
10
 
11
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(
12
+ model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
13
+ )
14
+ model.to(device)
15
+
16
+ processor = AutoProcessor.from_pretrained(model_id)
17
+
18
+ pipe = pipeline(
19
+ "automatic-speech-recognition",
20
+ model=model,
21
+ tokenizer=processor.tokenizer,
22
+ feature_extractor=processor.feature_extractor,
23
+ max_new_tokens=128,
24
+ chunk_length_s=30,
25
+ batch_size=16,
26
+ return_timestamps=True,
27
+ torch_dtype=torch_dtype,
28
+ device=device,
29
+ )
30
+
31
+ dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
32
+ sample = dataset[0]["audio"]
33
+
34
+ result = pipe(sample)
35
+ print(result["text"])