Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,44 +1,40 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
-
|
| 4 |
-
import wave
|
| 5 |
import matplotlib.pyplot as plt
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
def
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
return "Ошибка: WAV файл должен быть монофоническим."
|
| 15 |
-
|
| 16 |
-
# Читаем данные WAV файла
|
| 17 |
-
wav_data = np.frombuffer(wav_file.readframes(n_frames), dtype=np.int16)
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
fig, ax = plt.subplots()
|
| 25 |
-
ax.imshow(image)
|
| 26 |
-
ax.axis('off')
|
| 27 |
-
buf = BytesIO()
|
| 28 |
-
plt.savefig(buf, format="png")
|
| 29 |
-
buf.seek(0)
|
| 30 |
-
return buf
|
| 31 |
-
except Exception as e:
|
| 32 |
-
return f"Ошибка: {e}"
|
| 33 |
|
| 34 |
-
#
|
| 35 |
iface = gr.Interface(
|
| 36 |
-
fn=
|
| 37 |
-
inputs=gr.
|
| 38 |
-
outputs=
|
| 39 |
-
title="SSTV
|
| 40 |
-
description="
|
| 41 |
)
|
| 42 |
|
| 43 |
-
#
|
| 44 |
iface.launch()
|
|
|
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
+
import scipy.signal
|
|
|
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
def dummy_sstv_decode(audio_data, sample_rate):
|
| 7 |
+
"""
|
| 8 |
+
A placeholder function for decoding SSTV signals.
|
| 9 |
+
For a real decoder, you would process the audio_data to extract image information.
|
| 10 |
+
"""
|
| 11 |
+
# In a real implementation, you'd process the audio to extract an image.
|
| 12 |
+
# Here, we just return a blank image for demonstration purposes.
|
| 13 |
+
image = np.zeros((256, 320, 3), dtype=np.uint8)
|
| 14 |
+
return image
|
| 15 |
|
| 16 |
+
def sstv_decoder(audio_file):
|
| 17 |
+
# Load the audio file
|
| 18 |
+
sample_rate, audio_data = scipy.io.wavfile.read(audio_file.name)
|
| 19 |
+
|
| 20 |
+
# Decode the SSTV signal (Dummy Function)
|
| 21 |
+
image = dummy_sstv_decode(audio_data, sample_rate)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
# Display the image
|
| 24 |
+
plt.imshow(image)
|
| 25 |
+
plt.axis('off')
|
| 26 |
+
plt.show()
|
| 27 |
|
| 28 |
+
return image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
# Set up Gradio interface
|
| 31 |
iface = gr.Interface(
|
| 32 |
+
fn=sstv_decoder,
|
| 33 |
+
inputs=gr.Audio(source="upload", type="filepath"),
|
| 34 |
+
outputs="image",
|
| 35 |
+
title="SSTV Decoder",
|
| 36 |
+
description="Upload an audio file with an SSTV signal to decode it into an image.",
|
| 37 |
)
|
| 38 |
|
| 39 |
+
# Launch the interface
|
| 40 |
iface.launch()
|