Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,21 +23,24 @@ load_dotenv()
|
|
| 23 |
client = AsyncClient(timeout=30)
|
| 24 |
|
| 25 |
|
| 26 |
-
async def
|
| 27 |
response = await client.post(
|
| 28 |
url="https://douatiz8x2itm3yn.us-east-1.aws.endpoints.huggingface.cloud/api/v1/audio/transcriptions",
|
| 29 |
headers={"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"},
|
| 30 |
files={"file": audio_to_bytes(audio)},
|
| 31 |
-
data={
|
| 32 |
-
"response_format": "text",
|
| 33 |
-
},
|
| 34 |
)
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
|
| 38 |
transcript = gr.Textbox(label="Transcript")
|
| 39 |
stream = Stream(
|
| 40 |
-
ReplyOnPause(transcribe
|
| 41 |
modality="audio",
|
| 42 |
mode="send",
|
| 43 |
additional_inputs=[transcript],
|
|
@@ -65,7 +68,16 @@ with gr.Blocks() as demo:
|
|
| 65 |
</h2>
|
| 66 |
"""
|
| 67 |
)
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
if __name__ == "__main__":
|
| 71 |
demo.launch(allowed_paths=["AV_Huggy.png"])
|
|
|
|
| 23 |
client = AsyncClient(timeout=30)
|
| 24 |
|
| 25 |
|
| 26 |
+
async def transcribe_file(audio: tuple[int, np.ndarray]):
|
| 27 |
response = await client.post(
|
| 28 |
url="https://douatiz8x2itm3yn.us-east-1.aws.endpoints.huggingface.cloud/api/v1/audio/transcriptions",
|
| 29 |
headers={"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"},
|
| 30 |
files={"file": audio_to_bytes(audio)},
|
| 31 |
+
data={"response_format": "text"},
|
|
|
|
|
|
|
| 32 |
)
|
| 33 |
+
return response.text
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
async def transcribe(audio: tuple[int, np.ndarray], transcript: str):
|
| 37 |
+
text = await transcribe_file(audio)
|
| 38 |
+
yield AdditionalOutputs(transcript + " " + text)
|
| 39 |
|
| 40 |
|
| 41 |
transcript = gr.Textbox(label="Transcript")
|
| 42 |
stream = Stream(
|
| 43 |
+
ReplyOnPause(transcribe),
|
| 44 |
modality="audio",
|
| 45 |
mode="send",
|
| 46 |
additional_inputs=[transcript],
|
|
|
|
| 68 |
</h2>
|
| 69 |
"""
|
| 70 |
)
|
| 71 |
+
with gr.Tabs():
|
| 72 |
+
with gr.Tab("Streaming"):
|
| 73 |
+
gr.Markdown("Grant access to the microphone and speak naturally. The transcript will be updated as you pause.")
|
| 74 |
+
stream.ui.render()
|
| 75 |
+
with gr.Tab("File Upload"):
|
| 76 |
+
gr.Interface(
|
| 77 |
+
fn=transcribe_file,
|
| 78 |
+
inputs=[gr.Audio(label="Upload Audio", sources=["upload", "microphone"])],
|
| 79 |
+
outputs=gr.Textbox(label="Transcript"),
|
| 80 |
+
)
|
| 81 |
|
| 82 |
if __name__ == "__main__":
|
| 83 |
demo.launch(allowed_paths=["AV_Huggy.png"])
|