Spaces:
Sleeping
Sleeping
Commit
·
e1f9906
1
Parent(s):
0b01cbe
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,60 +2,64 @@ import streamlit as st
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
#
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
#
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
#
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
#
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
#
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
#
|
| 58 |
-
|
| 59 |
-
#
|
| 60 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
|
| 5 |
+
from scipy.io.wavfile import write
|
| 6 |
+
import gradio as gr
|
| 7 |
+
import wavio
|
| 8 |
+
input_file = 'recorded.wav'
|
| 9 |
+
output_file = 'output_filtered_receiver.wav'
|
| 10 |
+
|
| 11 |
+
low_frequency = 18000
|
| 12 |
+
high_frequency = 19000
|
| 13 |
+
bit_duration = 0.007
|
| 14 |
+
sample_rate = 44100
|
| 15 |
+
amplitude_scaling_factor = 10.0
|
| 16 |
+
|
| 17 |
+
def record(audio):
|
| 18 |
+
"""
|
| 19 |
+
This function records audio and writes it to a .wav file.
|
| 20 |
+
Parameters:
|
| 21 |
+
audio (tuple): A tuple containing the sample rate and the audio data.
|
| 22 |
+
Returns:
|
| 23 |
+
str: A success message if the audio is recorded correctly, otherwise an error message.
|
| 24 |
+
"""
|
| 25 |
+
try:
|
| 26 |
+
# Check if the audio tuple contains exactly two elements
|
| 27 |
+
if len(audio) != 2:
|
| 28 |
+
return f"Error: Expected a tuple with 2 elements, but got {len(audio)}"
|
| 29 |
+
|
| 30 |
+
# Unpack the sample rate and data from the audio tuple
|
| 31 |
+
sr, data = audio
|
| 32 |
+
|
| 33 |
+
# Write the audio data to a .wav file
|
| 34 |
+
wavio.write("recorded.wav", data, sr)
|
| 35 |
+
|
| 36 |
+
# Call the filtered function to apply the bandpass filter to the audio data
|
| 37 |
+
filtered()
|
| 38 |
+
|
| 39 |
+
# Return a success message
|
| 40 |
+
return f"Audio receive correctly"
|
| 41 |
+
except Exception as e:
|
| 42 |
+
# If an error occurs, return an error message
|
| 43 |
+
return f"Error: {str(e)}"
|
| 44 |
+
|
| 45 |
+
with gr.Blocks() as demo:
|
| 46 |
+
btn_record = gr.Button(value="record")
|
| 47 |
+
btn_record.click(fn=record, inputs=input_audio, outputs=output_text)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
demo.launch()
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
######################## models
|
| 55 |
+
# model = pipeline("sentiment-analysis")
|
| 56 |
+
# st.title("Hugging Face Model Demo")
|
| 57 |
+
# input_text = st.text_input("Enter your text", "")
|
| 58 |
+
# if st.button("Analyze"):
|
| 59 |
+
# # Perform inference using the loaded model
|
| 60 |
+
# result = model(input_text)
|
| 61 |
+
# st.write("Prediction:", result[0]['label'], "| Score:", result[0]['score'])
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
|
| 65 |
|