ZennyKenny commited on
Commit
e4afaf8
·
verified ·
1 Parent(s): 55aeb9b

remove ad hoc record support

Browse files
Files changed (1) hide show
  1. app.py +13 -38
app.py CHANGED
@@ -7,9 +7,9 @@ import os
7
  import uuid
8
  import spaces # Ensure spaces is imported
9
 
10
- # Directory to save recorded audio files
11
  OUTPUT_DIR = os.getenv("HF_HOME", ".") # Use dynamic path or default to current directory
12
- OUTPUT_DIR = os.path.join(OUTPUT_DIR, "recorded_audio_files")
13
  os.makedirs(OUTPUT_DIR, exist_ok=True)
14
 
15
  def split_audio(audio_data, sr, chunk_duration=30):
@@ -70,49 +70,30 @@ def main():
70
 
71
  def process_audio(audio_input):
72
  try:
73
- # Debug input type and content
74
- print(f"Input type: {type(audio_input)}, Input: {audio_input}")
75
- if audio_input is None:
76
- raise ValueError("No audio input received. Please record or upload an audio file.")
77
-
78
- if isinstance(audio_input, tuple): # Recorded audio
79
- print("Handling recorded audio.")
80
- audio_data, sr = audio_input
81
- filename = f"recorded_audio_{uuid.uuid4().hex}.wav"
82
- temp_path = os.path.join(OUTPUT_DIR, filename)
83
- sf.write(temp_path, audio_data, sr)
84
- elif isinstance(audio_input, str): # Uploaded file path
85
- print("Handling uploaded audio.")
86
- if os.path.isdir(audio_input):
87
- raise ValueError("Input is a directory, not a file.")
88
- temp_path = audio_input
89
- else:
90
- raise ValueError("Unsupported audio input format.")
91
-
92
- # Transcribe the saved audio file
93
- transcription = transcribe_long_audio(temp_path, transcriber, chunk_duration=30)
94
  summary = summarizer(transcription, max_length=50, min_length=10, do_sample=False)[0]["summary_text"]
95
 
96
  # Cleanup old files
97
  cleanup_output_dir()
98
 
99
- return transcription, summary, temp_path
100
  except Exception as e:
101
  print(f"Error in process_audio: {e}")
102
  return f"Error processing audio: {e}", "", ""
103
 
104
- def stop_microphone():
105
- """Simulate stopping the microphone."""
106
- print("Microphone stopped.")
107
- return "Microphone stopped. Recording session has ended."
108
-
109
  with gr.Blocks() as interface:
110
  with gr.Row():
111
  with gr.Column():
112
- # Enable recording or file upload
113
- audio_input = gr.Audio(type="numpy", label="Record or Upload Audio")
114
  process_button = gr.Button("Process Audio")
115
- stop_button = gr.Button("Stop Recording")
116
  with gr.Column():
117
  transcription_output = gr.Textbox(label="Full Transcription", lines=10)
118
  summary_output = gr.Textbox(label="Summary", lines=5)
@@ -124,12 +105,6 @@ def main():
124
  outputs=[transcription_output, summary_output, audio_output]
125
  )
126
 
127
- stop_button.click(
128
- stop_microphone,
129
- inputs=[],
130
- outputs=[]
131
- )
132
-
133
  interface.launch(share=False)
134
 
135
  if __name__ == "__main__":
 
7
  import uuid
8
  import spaces # Ensure spaces is imported
9
 
10
+ # Directory to save processed audio files
11
  OUTPUT_DIR = os.getenv("HF_HOME", ".") # Use dynamic path or default to current directory
12
+ OUTPUT_DIR = os.path.join(OUTPUT_DIR, "processed_audio_files")
13
  os.makedirs(OUTPUT_DIR, exist_ok=True)
14
 
15
  def split_audio(audio_data, sr, chunk_duration=30):
 
70
 
71
  def process_audio(audio_input):
72
  try:
73
+ print(f"Processing uploaded audio: {audio_input}")
74
+ if not isinstance(audio_input, str):
75
+ raise ValueError("Invalid input type. Please upload a valid audio file.")
76
+ if os.path.isdir(audio_input):
77
+ raise ValueError("Input is a directory, not a file.")
78
+
79
+ # Transcribe the uploaded audio file
80
+ transcription = transcribe_long_audio(audio_input, transcriber, chunk_duration=30)
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  summary = summarizer(transcription, max_length=50, min_length=10, do_sample=False)[0]["summary_text"]
82
 
83
  # Cleanup old files
84
  cleanup_output_dir()
85
 
86
+ return transcription, summary, audio_input
87
  except Exception as e:
88
  print(f"Error in process_audio: {e}")
89
  return f"Error processing audio: {e}", "", ""
90
 
 
 
 
 
 
91
  with gr.Blocks() as interface:
92
  with gr.Row():
93
  with gr.Column():
94
+ # Only support file uploads
95
+ audio_input = gr.Audio(type="filepath", label="Upload Audio File")
96
  process_button = gr.Button("Process Audio")
 
97
  with gr.Column():
98
  transcription_output = gr.Textbox(label="Full Transcription", lines=10)
99
  summary_output = gr.Textbox(label="Summary", lines=5)
 
105
  outputs=[transcription_output, summary_output, audio_output]
106
  )
107
 
 
 
 
 
 
 
108
  interface.launch(share=False)
109
 
110
  if __name__ == "__main__":