portalniy-dev commited on
Commit
bc598c3
·
verified ·
1 Parent(s): 066c28a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -34
app.py CHANGED
@@ -1,44 +1,40 @@
1
- import gradio as gr
2
  import numpy as np
3
- from pysstv.color import Robot36
4
- import wave
5
  import matplotlib.pyplot as plt
6
- from io import BytesIO
 
 
 
 
 
 
 
 
 
 
7
 
8
- def decode_sstv(file):
9
- try:
10
- # Открываем WAV файл
11
- with wave.open(file.name, 'rb') as wav_file:
12
- n_channels, sampwidth, framerate, n_frames, comptype, compname = wav_file.getparams()
13
- if n_channels != 1:
14
- return "Ошибка: WAV файл должен быть монофоническим."
15
-
16
- # Читаем данные WAV файла
17
- wav_data = np.frombuffer(wav_file.readframes(n_frames), dtype=np.int16)
18
 
19
- # Декодируем SSTV
20
- sstv = Robot36(wav_data, framerate)
21
- image = sstv.decode()
 
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
- # Интерфейс Gradio
35
  iface = gr.Interface(
36
- fn=decode_sstv,
37
- inputs=gr.File(label="Загрузите WAV файл (SSTV)"),
38
- outputs=gr.Image(type="file", label="Декодированное изображение"),
39
- title="SSTV Декодер",
40
- description="Загрузите WAV файл с SSTV сигналом для декодирования изображения."
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()