Spaces:
Running
Running
futurespyhi
commited on
Commit
·
1fba260
1
Parent(s):
7ef5bb3
Fix API key validation and Gradio chatbot format issues
Browse files- Remove unused OPENAI_API_KEY requirement and update to use GEMINI_API_KEY
- Fix Gradio chatbot format errors by ensuring all functions return proper [user, assistant] tuple format
- Resolve 'Data incompatible with tuples format' errors in respond() and response_audio() functions
app.py
CHANGED
|
@@ -226,7 +226,7 @@ class AppState:
|
|
| 226 |
|
| 227 |
def validate_api_keys():
|
| 228 |
"""Validate required API keys for Spaces deployment"""
|
| 229 |
-
required_keys = ["GROQ_API_KEY",
|
| 230 |
missing_keys = []
|
| 231 |
|
| 232 |
for key in required_keys:
|
|
@@ -399,7 +399,14 @@ def respond(message, state):
|
|
| 399 |
except Exception as e:
|
| 400 |
error_response = f"Sorry, I encountered an error: {str(e)}"
|
| 401 |
state.conversation.append({"role": "assistant", "content": error_response})
|
| 402 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 403 |
|
| 404 |
def build_interface():
|
| 405 |
"""Build the Gradio interface optimized for Spaces with high performance"""
|
|
@@ -666,7 +673,7 @@ def response_audio(state: AppState, audio: tuple, genre_value, mood_value, theme
|
|
| 666 |
Process recorded audio and generate a response based on transcription.
|
| 667 |
"""
|
| 668 |
if not audio:
|
| 669 |
-
return state,
|
| 670 |
|
| 671 |
# Update state with current dropdown values
|
| 672 |
state.genre, state.mood, state.theme = genre_value, mood_value, theme_value
|
|
@@ -698,7 +705,13 @@ def response_audio(state: AppState, audio: tuple, genre_value, mood_value, theme
|
|
| 698 |
|
| 699 |
os.remove(file_name)
|
| 700 |
|
| 701 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 702 |
|
| 703 |
def extract_lyrics_from_conversation(conversation):
|
| 704 |
"""
|
|
|
|
| 226 |
|
| 227 |
def validate_api_keys():
|
| 228 |
"""Validate required API keys for Spaces deployment"""
|
| 229 |
+
required_keys = ["GROQ_API_KEY", "GEMINI_API_KEY"]
|
| 230 |
missing_keys = []
|
| 231 |
|
| 232 |
for key in required_keys:
|
|
|
|
| 399 |
except Exception as e:
|
| 400 |
error_response = f"Sorry, I encountered an error: {str(e)}"
|
| 401 |
state.conversation.append({"role": "assistant", "content": error_response})
|
| 402 |
+
|
| 403 |
+
# Format conversation for display
|
| 404 |
+
conversation_display = []
|
| 405 |
+
for msg in state.conversation:
|
| 406 |
+
conversation_display.append([msg["content"] if msg["role"] == "user" else None,
|
| 407 |
+
msg["content"] if msg["role"] == "assistant" else None])
|
| 408 |
+
|
| 409 |
+
return "", conversation_display, state
|
| 410 |
|
| 411 |
def build_interface():
|
| 412 |
"""Build the Gradio interface optimized for Spaces with high performance"""
|
|
|
|
| 673 |
Process recorded audio and generate a response based on transcription.
|
| 674 |
"""
|
| 675 |
if not audio:
|
| 676 |
+
return state, []
|
| 677 |
|
| 678 |
# Update state with current dropdown values
|
| 679 |
state.genre, state.mood, state.theme = genre_value, mood_value, theme_value
|
|
|
|
| 705 |
|
| 706 |
os.remove(file_name)
|
| 707 |
|
| 708 |
+
# Format conversation for display
|
| 709 |
+
conversation_display = []
|
| 710 |
+
for msg in state.conversation:
|
| 711 |
+
conversation_display.append([msg["content"] if msg["role"] == "user" else None,
|
| 712 |
+
msg["content"] if msg["role"] == "assistant" else None])
|
| 713 |
+
|
| 714 |
+
return state, conversation_display
|
| 715 |
|
| 716 |
def extract_lyrics_from_conversation(conversation):
|
| 717 |
"""
|