TheStinger commited on
Commit
beee88e
·
1 Parent(s): 418f3eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -34
app.py CHANGED
@@ -1,36 +1,17 @@
1
  import gradio as gr
2
- from pydub import AudioSegment
3
-
4
- def calcola_valore_da_audio(file_audio):
5
- try:
6
- # Estrarre il percorso del file dalla tupla (potrebbe variare a seconda di come Gradio gestisce l'input)
7
- file_audio_path = file_audio[0] if isinstance(file_audio, tuple) else file_audio
8
-
9
- # Apri e gestisci correttamente il file audio
10
- with open(file_audio_path, 'rb') as file:
11
- audio = AudioSegment.from_file(file)
12
-
13
- # Calcola la lunghezza dell'audio in minuti
14
- lunghezza_audio_minuti = len(audio) / (1000 * 60) # la durata di default di pydub è in millisecondi
15
-
16
- # Calcola il valore in base alla lunghezza dell'audio
17
- valore = lunghezza_audio_minuti * 100
18
-
19
- return f"Valore calcolato: {valore:.2f}"
20
-
21
- except Exception as e:
22
- return f"Errore durante l'elaborazione del file audio: {str(e)}"
23
-
24
- # Creare un'interfaccia Gradio
25
- iface = gr.Interface(
26
- fn=calcola_valore_da_audio,
27
- inputs="audio",
28
- outputs="text",
29
- live=True,
30
- title="Calcolatore Valore da Audio",
31
- description="Inserisci un file audio e otterrai un valore in base alla sua lunghezza.",
32
- allow_flagging=False
33
- )
34
-
35
- # Avvia l'interfaccia Gradio
36
  iface.launch()
 
1
  import gradio as gr
2
+ import librosa
3
+
4
+ def calculate_epochs(audio_file):
5
+ # Carica il file audio
6
+ y, sr = librosa.load(audio_file, sr=None)
7
+
8
+ # Calcola la durata in minuti
9
+ duration = librosa.get_duration(y, sr) / 60
10
+
11
+ # Calcola il numero di epoche
12
+ epochs = int(duration * 100)
13
+
14
+ return epochs
15
+
16
+ iface = gr.Interface(fn=calculate_epochs, inputs="file", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  iface.launch()