startrz commited on
Commit
4ba2f2a
·
verified ·
1 Parent(s): 05a30e5

Update requirements.txt

Browse files
Files changed (1) hide show
  1. requirements.txt +94 -3
requirements.txt CHANGED
@@ -1,3 +1,94 @@
1
- streamlit
2
- requests
3
- tiktoken
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import base64
4
+ import json
5
+ from io import BytesIO
6
+ import numpy as np
7
+ from audio_recorder_streamlit import audio_recorder
8
+
9
+ def convert_audio_to_base64(audio_bytes):
10
+ """Convert audio bytes to base64 string"""
11
+ if audio_bytes is None:
12
+ return None
13
+ base64_str = base64.b64encode(audio_bytes).decode('utf-8')
14
+ return f"data:audio/webm;codecs=opus;base64,{base64_str}"
15
+
16
+ def query_prediction_api(audio_base64):
17
+ """Send request to prediction API"""
18
+ url = "http://localhost:3000/api/v1/prediction/<chatlfowid>"
19
+
20
+ payload = {
21
+ "uploads": [
22
+ {
23
+ "data": audio_base64,
24
+ "type": "audio",
25
+ "name": "audio.wav",
26
+ "mime": "audio/webm"
27
+ }
28
+ ]
29
+ }
30
+
31
+ try:
32
+ response = requests.post(
33
+ url,
34
+ headers={"Content-Type": "application/json"},
35
+ json=payload
36
+ )
37
+ response.raise_for_status()
38
+ return response.json()
39
+ except requests.exceptions.RequestException as e:
40
+ st.error(f"Error making prediction: {str(e)}")
41
+ return None
42
+
43
+ def main():
44
+ st.title("Audio Prediction App")
45
+ st.write("Record or upload audio to get predictions")
46
+
47
+ # Add tabs for different input methods
48
+ tab1, tab2 = st.tabs(["Record Audio", "Upload Audio"])
49
+
50
+ with tab1:
51
+ st.write("Click the button below to record audio")
52
+ audio_bytes = audio_recorder()
53
+
54
+ if audio_bytes:
55
+ st.audio(audio_bytes, format="audio/webm")
56
+
57
+ if st.button("Get Prediction for Recorded Audio"):
58
+ with st.spinner("Getting prediction..."):
59
+ audio_base64 = convert_audio_to_base64(audio_bytes)
60
+ if audio_base64:
61
+ prediction = query_prediction_api(audio_base64)
62
+ if prediction:
63
+ st.json(prediction)
64
+
65
+ with tab2:
66
+ uploaded_file = st.file_uploader("Choose an audio file", type=['wav', 'mp3', 'webm'])
67
+
68
+ if uploaded_file:
69
+ audio_bytes = uploaded_file.read()
70
+ st.audio(audio_bytes)
71
+
72
+ if st.button("Get Prediction for Uploaded Audio"):
73
+ with st.spinner("Getting prediction..."):
74
+ audio_base64 = convert_audio_to_base64(audio_bytes)
75
+ if audio_base64:
76
+ prediction = query_prediction_api(audio_base64)
77
+ if prediction:
78
+ st.json(prediction)
79
+
80
+ st.sidebar.markdown("""
81
+ ### About
82
+ This app allows you to:
83
+ - Record audio directly in the browser
84
+ - Upload audio files
85
+ - Get predictions from the API
86
+
87
+ Supported formats:
88
+ - WAV
89
+ - MP3
90
+ - WebM
91
+ """)
92
+
93
+ if __name__ == "__main__":
94
+ main()