omarxadel commited on
Commit
6249202
1 Parent(s): 9562dfe

feat: created gradio app with model

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. app.py +36 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .idea
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import HubertForCTC, Wav2Vec2Processor
2
+ import gradio as gr
3
+ import time
4
+ import torch
5
+ import soundfile as sf
6
+ import requests
7
+
8
+ API_URL = "https://api-inference.huggingface.co/models/omarxadel/hubert-large-arabic-egyptian"
9
+ token = os.environ['apikey']
10
+ headers = {"Authorization": token}
11
+
12
+
13
+ def transcribe(audio, state=""):
14
+ time.sleep(2)
15
+
16
+ # Load model from HuggingFace Hub
17
+ with open(audio, "rb") as f:
18
+ data = f.read()
19
+ response = requests.post(API_URL, headers=headers, data=data)
20
+ output = response.json()["text"]
21
+ state += output + " "
22
+ return state, state
23
+
24
+
25
+ gr.Interface(
26
+ fn=transcribe,
27
+ inputs=[
28
+ gr.Audio(source="microphone", type="filepath", streaming=True),
29
+ "state"
30
+ ],
31
+ outputs=[
32
+ "textbox",
33
+ "state"
34
+ ],
35
+ live=True).launch(share=True)
36
+