RanAlh443 commited on
Commit
c9abb42
·
verified ·
1 Parent(s): 59019c2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ def process_audio(audio_file, min_length, max_length):
3
+ try:
4
+
5
+ # Ensure audio_file is not None and has valid content
6
+ if audio_file is None:
7
+ raise ValueError("The audio file is missing or invalid.")
8
+
9
+ result = whisper_model.transcribe(audio_file)
10
+ text = result['text']
11
+ if not text:
12
+ raise ValueError("Failed to transcribe the audio. The transcription result is empty.")
13
+
14
+ summary_result = summarization(text, max_length=max_length, min_length=min_length)
15
+ summary = summary_result[0]['summary_text']
16
+ if not summary:
17
+ raise ValueError("Failed to summarize the transcript. The summary result is empty.")
18
+
19
+ df_results = pd.DataFrame({
20
+ "Audio File": [audio_file],
21
+ "Transcript": [text],
22
+ "Summary": [summary]
23
+ })
24
+
25
+ df_results.to_csv("results.csv", index=False)
26
+
27
+ return text, summary
28
+ except Exception as e:
29
+ # General error handling
30
+ error_message = f"An error occurred: {str(e)}"
31
+ print(error_message) # Print the error for debugging
32
+ return error_message, error_message
33
+
34
+ iface = gr.Interface(
35
+ fn=process_audio,
36
+ inputs=[
37
+ gr.Audio(sources="upload", type="filepath", label="Upload your audio file"),
38
+ gr.Slider(minimum=5, maximum=50, value=30, label="Minimum Summary Length"),
39
+ gr.Slider(minimum=50, maximum=500, value=150, label="Maximum Summary Length")
40
+ ],
41
+ outputs=[
42
+ gr.Textbox(label="Transcript"),
43
+ gr.Textbox(label="Summary")
44
+ ],
45
+ title="Audio to Summarized Transcript",
46
+ description="Upload an audio file and adjust summary length to get both the transcript and summary."
47
+ )
48
+
49
+ iface.launch()