portalniy-dev commited on
Commit
7898d98
·
verified ·
1 Parent(s): 20c43d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -29
app.py CHANGED
@@ -1,40 +1,33 @@
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()
 
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 сигнала, установка sample_rate после создания объек
13
+ sstv = Robot36(samples)
14
+ sstv.sample_rate = audio.frame_rate
15
+ img = sstv.decode()
 
 
16
 
17
+ # Отображение изображения
18
+ plt.imshow(img)
19
  plt.axis('off')
20
+ img_path = 'decoded_image.png'
21
+ plt.savefig(img_path, bbox_inches='tight', pad_inches=0)
22
+ return img_path
23
 
 
 
 
24
  iface = gr.Interface(
25
+ fn=decode_sstv,
26
+ inputs=gr.Audio(type="filepath", label="Upload SSTV Audio File"),
27
+ outputs=gr.Image(label="Decoded Image"),
28
  title="SSTV Decoder",
29
+ description="Upload an SSTV audio file to decode the image."
30
  )
31
 
32
+ if __name__ == "__main__":
33
+ iface.launch()