emmajeed commited on
Commit
df8ba4d
Β·
verified Β·
1 Parent(s): 5fdd6f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -40
app.py CHANGED
@@ -8,19 +8,13 @@ import os
8
  from transcribe_core import process_audio_file, get_audio_duration
9
  from ai_providers import GeminiProvider, OpenRouterProvider
10
 
 
 
 
11
 
12
  def transcribe_audio(audio_file, gemini_key, openrouter_key, model_name):
13
  """
14
  Main transcription function for Gradio interface.
15
-
16
- Args:
17
- audio_file: Uploaded audio file
18
- gemini_key: Gemini API key for transcription
19
- openrouter_key: OpenRouter API key for summary/ideas
20
- model_name: Gemini model to use
21
-
22
- Returns:
23
- Tuple of (status_message, download_file_path)
24
  """
25
  if not audio_file:
26
  return "❌ Please upload an audio file.", None
@@ -42,7 +36,7 @@ def transcribe_audio(audio_file, gemini_key, openrouter_key, model_name):
42
  duration_min = duration / 60
43
  file_size_mb = os.path.getsize(audio_file) / (1024 * 1024)
44
 
45
- # Process the audio file
46
  output_path, is_zip = process_audio_file(
47
  audio_file,
48
  gemini_provider,
@@ -51,7 +45,7 @@ def transcribe_audio(audio_file, gemini_key, openrouter_key, model_name):
51
  )
52
 
53
  # Determine file type for success message
54
- if is_zip == "True":
55
  file_type = "ZIP archive"
56
  file_desc = "Multiple transcript files (chunked audio)"
57
  else:
@@ -73,7 +67,7 @@ def transcribe_audio(audio_file, gemini_key, openrouter_key, model_name):
73
 
74
  Click below to download your transcript(s)."""
75
 
76
- # Return the file path directly - Gradio handles the download
77
  return success_msg, output_path
78
 
79
  except Exception as e:
@@ -141,10 +135,10 @@ with gr.Blocks(title="Transcriptinator", theme=gr.themes.Soft()) as app:
141
  # Status output
142
  status_output = gr.Markdown(label="Status")
143
 
144
- # Download button
145
- download_output = gr.File(label="πŸ“₯ Download Transcript", interactive=False)
146
 
147
- # Information section
148
  gr.Markdown("""
149
  ---
150
  ### 🎯 What you'll get:
@@ -152,29 +146,6 @@ with gr.Blocks(title="Transcriptinator", theme=gr.themes.Soft()) as app:
152
  - πŸ“Š **Summary** in 2-3 sentences
153
  - πŸ’‘ **Key ideas** with descriptions
154
  - πŸ“„ **Markdown file** ready to download
155
-
156
- ### πŸ€– AI Models:
157
-
158
- **Gemini** (Google) - Transcription:
159
- - Gemini 2.5 Flash (recommended - fastest, best quality)
160
- - Gemini 2.0 Flash (experimental)
161
- - Gemini 1.5 Flash (stable)
162
- - Native audio support with timestamps and speakers
163
-
164
- **OpenRouter** (Optional) - Summarization:
165
- - Uses DeepSeek R1 (free, excellent reasoning)
166
- - Better summaries and key ideas extraction
167
- - Leave API key empty to use Gemini for everything
168
-
169
- ### πŸ”’ Privacy:
170
- - Your API keys are never stored
171
- - Audio files are processed temporarily and deleted
172
- - All processing happens through your own credentials
173
-
174
- ### πŸ’‘ Tips:
175
- - **New users:** Start with just Gemini API key
176
- - **Better summaries:** Add OpenRouter key (optional, free)
177
- - **Large files:** App automatically chunks files >30MB
178
  """)
179
 
180
  # Connect the transcription function
@@ -184,6 +155,7 @@ with gr.Blocks(title="Transcriptinator", theme=gr.themes.Soft()) as app:
184
  outputs=[status_output, download_output]
185
  )
186
 
187
- # Launch the app with queuing enabled
188
  if __name__ == "__main__":
189
- app.queue().launch()
 
 
8
  from transcribe_core import process_audio_file, get_audio_duration
9
  from ai_providers import GeminiProvider, OpenRouterProvider
10
 
11
+ # Establish absolute paths for Hugging Face Spaces compatibility
12
+ CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
13
+ OUTPUT_FOLDER = os.path.join(CURRENT_DIR, "outputs")
14
 
15
  def transcribe_audio(audio_file, gemini_key, openrouter_key, model_name):
16
  """
17
  Main transcription function for Gradio interface.
 
 
 
 
 
 
 
 
 
18
  """
19
  if not audio_file:
20
  return "❌ Please upload an audio file.", None
 
36
  duration_min = duration / 60
37
  file_size_mb = os.path.getsize(audio_file) / (1024 * 1024)
38
 
39
+ # Process the audio file - ensure this function in core uses absolute paths
40
  output_path, is_zip = process_audio_file(
41
  audio_file,
42
  gemini_provider,
 
45
  )
46
 
47
  # Determine file type for success message
48
+ if str(is_zip) == "True":
49
  file_type = "ZIP archive"
50
  file_desc = "Multiple transcript files (chunked audio)"
51
  else:
 
67
 
68
  Click below to download your transcript(s)."""
69
 
70
+ # Return the absolute file path - Gradio handles the download via proxy
71
  return success_msg, output_path
72
 
73
  except Exception as e:
 
135
  # Status output
136
  status_output = gr.Markdown(label="Status")
137
 
138
+ # Download component - removed 'interactive=False' for better stability
139
+ download_output = gr.File(label="πŸ“₯ Download Transcript")
140
 
141
+ # Information section ... (remains unchanged)
142
  gr.Markdown("""
143
  ---
144
  ### 🎯 What you'll get:
 
146
  - πŸ“Š **Summary** in 2-3 sentences
147
  - πŸ’‘ **Key ideas** with descriptions
148
  - πŸ“„ **Markdown file** ready to download
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  """)
150
 
151
  # Connect the transcription function
 
155
  outputs=[status_output, download_output]
156
  )
157
 
158
+ # Launch the app with queuing and allowed_paths for file access
159
  if __name__ == "__main__":
160
+ os.makedirs(OUTPUT_FOLDER, exist_ok=True)
161
+ app.queue().launch(allowed_paths=[OUTPUT_FOLDER])