Spaces:
Running
Running
<html> | |
<head> | |
<title>Gradio App</title> | |
<script src="https://cdn.jsdelivr.net/npm/@gradio/[email protected]/dist/gradio.min.js"></script> | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
height: 100vh; | |
margin: 0; | |
background-color: #f0f0f0; | |
} | |
#app { | |
width: 80%; | |
max-width: 600px; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="app"></div> | |
<script> | |
const app = new gradio.App({ cors: true }); | |
function transcribeAudio(audio) { | |
return new Promise((resolve, reject) => { | |
const reader = new FileReader(); | |
reader.readAsDataURL(audio); | |
reader.onloadend = () => { | |
const base64data = reader.result.split(',')[1]; // Encode audio to base64 | |
fetch('/api/transcribe', { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({ audio: base64data }) | |
}) | |
.then(response => response.json()) | |
.then(data => resolve(data.transcription)) | |
.catch(error => reject('Error transcribing audio: ' + error)); | |
}; | |
}); | |
} | |
app.launch(() => { | |
return [ | |
gradio.Audio({ label: "Spracheingabe" }), | |
gradio.Textbox({ label: "Textausgabe" }) | |
]; | |
}, { | |
fn: transcribeAudio, | |
inputs: "audio", | |
outputs: "textbox", | |
title: "Sprachtranskription", | |
description: "Lade eine Audioaufnahme hoch oder spreche direkten Text ein." | |
}); | |
</script> | |
</body> | |
</html> | |