portalniy-dev commited on
Commit
ee5b9d0
·
verified ·
1 Parent(s): 1dd0560

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from pydub import AudioSegment
3
+ from matplotlib import pyplot as plt
4
+ from pysstv.color import Robot36
5
+ import gradio as gr
6
+
7
+ def decode_sstv(audio_file):
8
+ # Чтение аудиофайла
9
+ audio = AudioSegment.from_file(audio_file)
10
+ samples = np.array(audio.get_array_of_samples(), dtype=np.int16)
11
+
12
+ # Декодирование SSTV сигнала
13
+ sstv = Robot36(samples, sample_rate=audio.frame_rate)
14
+ img = sstv.decode()
15
+
16
+ # Отображение изображения
17
+ plt.imshow(img)
18
+ plt.axis('off')
19
+ img_path = 'decoded_image.png'
20
+ plt.savefig(img_path, bbox_inches='tight', pad_inches=0)
21
+ return img_path
22
+
23
+ iface = gr.Interface(
24
+ fn=decode_sstv,
25
+ inputs=gr.Audio(source="upload", type="file", label="Upload SSTV Audio File"),
26
+ outputs=gr.Image(label="Decoded Image"),
27
+ title="SSTV Decoder",
28
+ description="Upload an SSTV audio file to decode the image."
29
+ )
30
+
31
+ if __name__ == "__main__":
32
+ iface.launch()