Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
import streamlit as st
|
2 |
-
import torch
|
3 |
import os
|
|
|
4 |
import soundfile as sf
|
5 |
from groq import Groq
|
6 |
from diffusers import AutoPipelineForText2Image
|
|
|
7 |
|
8 |
# Load API keys
|
9 |
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
@@ -22,7 +23,7 @@ def transcribe(audio_path):
|
|
22 |
transcription = client.audio.transcriptions.create(
|
23 |
file=(audio_path, file.read()),
|
24 |
model="whisper-large-v3",
|
25 |
-
language="ta",
|
26 |
response_format="verbose_json"
|
27 |
)
|
28 |
return transcription["text"]
|
@@ -54,21 +55,25 @@ st.title("Tamil Speech to Image & Story Generator")
|
|
54 |
# Choose input method
|
55 |
input_method = st.radio("Choose Input Method:", ("Record Audio", "Upload Audio"))
|
56 |
|
|
|
|
|
57 |
if input_method == "Record Audio":
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
elif input_method == "Upload Audio":
|
60 |
uploaded_file = st.file_uploader("Upload an audio file", type=["wav", "mp3"])
|
61 |
-
|
62 |
-
if st.button("Generate"):
|
63 |
-
if input_method == "Record Audio" and recorded_audio:
|
64 |
-
audio_data, samplerate = sf.read(recorded_audio)
|
65 |
-
audio_path = "recorded_audio.wav"
|
66 |
-
sf.write(audio_path, audio_data, samplerate)
|
67 |
-
elif input_method == "Upload Audio" and uploaded_file:
|
68 |
audio_path = "uploaded_audio.wav"
|
69 |
with open(audio_path, "wb") as f:
|
70 |
f.write(uploaded_file.getbuffer())
|
71 |
-
|
|
|
|
|
72 |
st.error("Please provide an audio file.")
|
73 |
st.stop()
|
74 |
|
|
|
1 |
import streamlit as st
|
|
|
2 |
import os
|
3 |
+
import torch
|
4 |
import soundfile as sf
|
5 |
from groq import Groq
|
6 |
from diffusers import AutoPipelineForText2Image
|
7 |
+
from streamlit_webrtc import webrtc_streamer, AudioRecorder
|
8 |
|
9 |
# Load API keys
|
10 |
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
|
|
23 |
transcription = client.audio.transcriptions.create(
|
24 |
file=(audio_path, file.read()),
|
25 |
model="whisper-large-v3",
|
26 |
+
language="ta",
|
27 |
response_format="verbose_json"
|
28 |
)
|
29 |
return transcription["text"]
|
|
|
55 |
# Choose input method
|
56 |
input_method = st.radio("Choose Input Method:", ("Record Audio", "Upload Audio"))
|
57 |
|
58 |
+
audio_path = None
|
59 |
+
|
60 |
if input_method == "Record Audio":
|
61 |
+
st.subheader("Record your Tamil speech")
|
62 |
+
recorder = webrtc_streamer(key="record_audio", audio=True)
|
63 |
+
|
64 |
+
if recorder.audio_receiver:
|
65 |
+
audio_data = recorder.audio_receiver.get_frames() # Get recorded audio
|
66 |
+
audio_path = "recorded_audio.wav"
|
67 |
+
sf.write(audio_path, audio_data, 16000) # Save recorded audio
|
68 |
elif input_method == "Upload Audio":
|
69 |
uploaded_file = st.file_uploader("Upload an audio file", type=["wav", "mp3"])
|
70 |
+
if uploaded_file:
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
audio_path = "uploaded_audio.wav"
|
72 |
with open(audio_path, "wb") as f:
|
73 |
f.write(uploaded_file.getbuffer())
|
74 |
+
|
75 |
+
if st.button("Generate"):
|
76 |
+
if not audio_path:
|
77 |
st.error("Please provide an audio file.")
|
78 |
st.stop()
|
79 |
|