jahnavib26 commited on
Commit
b09aad8
·
verified ·
1 Parent(s): 8653044

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -15
app.py CHANGED
@@ -1,6 +1,5 @@
1
- import gradio as gr
2
- from transformers import pipeline
3
  import torch
 
4
  from datasets import load_dataset
5
 
6
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
@@ -12,18 +11,13 @@ pipe = pipeline(
12
  device=device,
13
  )
14
 
15
- pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
 
16
 
17
- def predict(input_img):
18
- predictions = pipeline(input_img)
19
- return input_img, {p["label"]: p["score"] for p in predictions}
20
-
21
- gradio_app = gr.Interface(
22
- predict,
23
- inputs=gr.Image(label="Select hot dog candidate", sources=['upload', 'webcam'], type="pil"),
24
- outputs=[gr.Image(label="Processed Image"), gr.Label(label="Result", num_top_classes=2)],
25
- title="Hot Dog? Or Not?",
26
- )
27
 
28
- if __name__ == "__main__":
29
- gradio_app.launch()
 
 
 
 
 
1
  import torch
2
+ from transformers import pipeline
3
  from datasets import load_dataset
4
 
5
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
 
11
  device=device,
12
  )
13
 
14
+ ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
15
+ sample = ds[0]["audio"]
16
 
17
+ prediction = pipe(sample.copy(), batch_size=8)["text"]
18
+ " Mr. Quilter is the apostle of the middle classes, and we are glad to welcome his gospel."
 
 
 
 
 
 
 
 
19
 
20
+ # we can also return timestamps for the predictions
21
+ prediction = pipe(sample.copy(), batch_size=8, return_timestamps=True)["chunks"]
22
+ [{'text': ' Mr. Quilter is the apostle of the middle classes and we are glad to welcome his gospel.',
23
+ 'timestamp': (0.0, 5.44)}]