Spaces:
Runtime error
Runtime error
Yes
Browse files
app.py
CHANGED
|
@@ -5,8 +5,7 @@ from typing import Optional, Tuple
|
|
| 5 |
import tempfile
|
| 6 |
|
| 7 |
import gradio as gr
|
| 8 |
-
|
| 9 |
-
from google.genai import types
|
| 10 |
|
| 11 |
# Supported input audio formats
|
| 12 |
SUPPORTED_AUDIO_EXTS = {".wav", ".mp3", ".m4a"}
|
|
@@ -187,7 +186,6 @@ def normalize_audio_file(audio_path: str) -> str:
|
|
| 187 |
|
| 188 |
|
| 189 |
def generate_text_with_optional_audio(
|
| 190 |
-
client: genai.Client,
|
| 191 |
model: str,
|
| 192 |
prompt: str,
|
| 193 |
system_prompt: Optional[str] = None,
|
|
@@ -197,65 +195,42 @@ def generate_text_with_optional_audio(
|
|
| 197 |
Call Gemini with text prompt and optional audio file.
|
| 198 |
Returns the model's text response.
|
| 199 |
"""
|
| 200 |
-
contents
|
| 201 |
|
| 202 |
if audio_path:
|
| 203 |
normalized = normalize_audio_file(audio_path)
|
| 204 |
-
uploaded_file =
|
| 205 |
contents.append(uploaded_file)
|
| 206 |
|
| 207 |
effective_system_prompt = system_prompt or DEFAULT_SYSTEM_PROMPT
|
| 208 |
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
config=types.GenerateContentConfig(
|
| 213 |
-
system_instruction=effective_system_prompt,
|
| 214 |
-
),
|
| 215 |
)
|
| 216 |
-
|
|
|
|
| 217 |
return response.text
|
| 218 |
|
| 219 |
|
| 220 |
def tts_from_text(
|
| 221 |
-
client: genai.Client,
|
| 222 |
text: str,
|
| 223 |
-
model: str = "gemini-
|
| 224 |
voice_name: str = "Kore",
|
| 225 |
) -> str:
|
| 226 |
"""
|
| 227 |
Convert text to speech using Gemini TTS and save to a WAV file.
|
| 228 |
Returns the path to the generated audio file.
|
|
|
|
| 229 |
"""
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
voice_config=types.VoiceConfig(
|
| 237 |
-
prebuilt_voice_config=types.PrebuiltVoiceConfig(
|
| 238 |
-
voice_name=voice_name
|
| 239 |
-
)
|
| 240 |
-
)
|
| 241 |
-
),
|
| 242 |
-
),
|
| 243 |
)
|
| 244 |
|
| 245 |
-
try:
|
| 246 |
-
data = response.candidates[0].content.parts[0].inline_data.data
|
| 247 |
-
except (IndexError, AttributeError, TypeError) as e:
|
| 248 |
-
raise RuntimeError(
|
| 249 |
-
f"Unexpected TTS response format: {e!r}\nFull response: {response}"
|
| 250 |
-
)
|
| 251 |
-
|
| 252 |
-
# Create temporary file for audio output
|
| 253 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp:
|
| 254 |
-
output_wav = tmp.name
|
| 255 |
-
|
| 256 |
-
wave_file(output_wav, data)
|
| 257 |
-
return output_wav
|
| 258 |
-
|
| 259 |
|
| 260 |
def process_meeting_notes(
|
| 261 |
operation_type: str,
|
|
@@ -278,7 +253,7 @@ def process_meeting_notes(
|
|
| 278 |
try:
|
| 279 |
# Initialize Gemini client
|
| 280 |
progress(0.1, desc="Initializing Gemini client...")
|
| 281 |
-
|
| 282 |
|
| 283 |
# Prepare prompt based on operation type
|
| 284 |
progress(0.2, desc="Preparing prompt...")
|
|
@@ -292,8 +267,7 @@ def process_meeting_notes(
|
|
| 292 |
# Generate text response
|
| 293 |
progress(0.4, desc="Processing with Gemini...")
|
| 294 |
text_response = generate_text_with_optional_audio(
|
| 295 |
-
|
| 296 |
-
model="gemini-2.0-flash-exp",
|
| 297 |
prompt=prompt,
|
| 298 |
system_prompt=DEFAULT_SYSTEM_PROMPT,
|
| 299 |
audio_path=audio_input,
|
|
@@ -305,13 +279,16 @@ def process_meeting_notes(
|
|
| 305 |
audio_output = None
|
| 306 |
if enable_tts:
|
| 307 |
progress(0.8, desc="Generating audio output...")
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
|
|
|
|
|
|
|
|
|
| 315 |
else:
|
| 316 |
progress(1.0, desc="Processing complete!")
|
| 317 |
|
|
@@ -444,4 +421,4 @@ with gr.Blocks(title="Meeting Notes Assistant", theme=gr.themes.Soft()) as demo:
|
|
| 444 |
|
| 445 |
|
| 446 |
if __name__ == "__main__":
|
| 447 |
-
demo.launch()
|
|
|
|
| 5 |
import tempfile
|
| 6 |
|
| 7 |
import gradio as gr
|
| 8 |
+
import google.generativeai as genai
|
|
|
|
| 9 |
|
| 10 |
# Supported input audio formats
|
| 11 |
SUPPORTED_AUDIO_EXTS = {".wav", ".mp3", ".m4a"}
|
|
|
|
| 186 |
|
| 187 |
|
| 188 |
def generate_text_with_optional_audio(
|
|
|
|
| 189 |
model: str,
|
| 190 |
prompt: str,
|
| 191 |
system_prompt: Optional[str] = None,
|
|
|
|
| 195 |
Call Gemini with text prompt and optional audio file.
|
| 196 |
Returns the model's text response.
|
| 197 |
"""
|
| 198 |
+
contents = [prompt]
|
| 199 |
|
| 200 |
if audio_path:
|
| 201 |
normalized = normalize_audio_file(audio_path)
|
| 202 |
+
uploaded_file = genai.upload_file(normalized)
|
| 203 |
contents.append(uploaded_file)
|
| 204 |
|
| 205 |
effective_system_prompt = system_prompt or DEFAULT_SYSTEM_PROMPT
|
| 206 |
|
| 207 |
+
model_instance = genai.GenerativeModel(
|
| 208 |
+
model_name=model,
|
| 209 |
+
system_instruction=effective_system_prompt,
|
|
|
|
|
|
|
|
|
|
| 210 |
)
|
| 211 |
+
|
| 212 |
+
response = model_instance.generate_content(contents)
|
| 213 |
return response.text
|
| 214 |
|
| 215 |
|
| 216 |
def tts_from_text(
|
|
|
|
| 217 |
text: str,
|
| 218 |
+
model: str = "gemini-1.5-flash",
|
| 219 |
voice_name: str = "Kore",
|
| 220 |
) -> str:
|
| 221 |
"""
|
| 222 |
Convert text to speech using Gemini TTS and save to a WAV file.
|
| 223 |
Returns the path to the generated audio file.
|
| 224 |
+
Note: TTS is not yet available in google.generativeai, returning placeholder.
|
| 225 |
"""
|
| 226 |
+
# TTS functionality is not yet available in the standard google.generativeai package
|
| 227 |
+
# This is a placeholder that returns None
|
| 228 |
+
# Users should use alternative TTS services like Google Cloud TTS or gTTS
|
| 229 |
+
raise NotImplementedError(
|
| 230 |
+
"TTS is not yet available in google.generativeai. "
|
| 231 |
+
"Please disable TTS output or use alternative TTS services."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
)
|
| 233 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
|
| 235 |
def process_meeting_notes(
|
| 236 |
operation_type: str,
|
|
|
|
| 253 |
try:
|
| 254 |
# Initialize Gemini client
|
| 255 |
progress(0.1, desc="Initializing Gemini client...")
|
| 256 |
+
genai.configure(api_key=api_key)
|
| 257 |
|
| 258 |
# Prepare prompt based on operation type
|
| 259 |
progress(0.2, desc="Preparing prompt...")
|
|
|
|
| 267 |
# Generate text response
|
| 268 |
progress(0.4, desc="Processing with Gemini...")
|
| 269 |
text_response = generate_text_with_optional_audio(
|
| 270 |
+
model="gemini-1.5-flash",
|
|
|
|
| 271 |
prompt=prompt,
|
| 272 |
system_prompt=DEFAULT_SYSTEM_PROMPT,
|
| 273 |
audio_path=audio_input,
|
|
|
|
| 279 |
audio_output = None
|
| 280 |
if enable_tts:
|
| 281 |
progress(0.8, desc="Generating audio output...")
|
| 282 |
+
try:
|
| 283 |
+
audio_output = tts_from_text(
|
| 284 |
+
text=text_response,
|
| 285 |
+
model="gemini-1.5-flash",
|
| 286 |
+
voice_name="Kore",
|
| 287 |
+
)
|
| 288 |
+
progress(1.0, desc="Audio generation complete!")
|
| 289 |
+
except NotImplementedError as tts_error:
|
| 290 |
+
progress(1.0, desc="Processing complete (TTS unavailable)")
|
| 291 |
+
return text_response + "\n\n⚠️ Note: " + str(tts_error), None
|
| 292 |
else:
|
| 293 |
progress(1.0, desc="Processing complete!")
|
| 294 |
|
|
|
|
| 421 |
|
| 422 |
|
| 423 |
if __name__ == "__main__":
|
| 424 |
+
demo.launch()
|