aiqcamp commited on
Commit
e8d7a57
·
verified ·
1 Parent(s): 24b5de4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -35,9 +35,10 @@ def stream_gemini_response(message_input: str|gr.File, messages: list) -> Iterat
35
  if isinstance(message_input, str):
36
  user_message = message_input
37
  print(f"\n=== New Request (Text) ===")
 
38
  print(f"User message: {user_message}")
39
- if not user_message.strip(): # Robust check: if text message is empty or whitespace
40
- messages.append(ChatMessage(role="assistant", content="Please provide a non-empty text message or upload a file.")) #More specific message
41
  yield messages
42
  return
43
 
@@ -142,6 +143,7 @@ def stream_gemini_response(message_input: str|gr.File, messages: list) -> Iterat
142
 
143
  print(f"\n=== Final Response ===\n{response_buffer}")
144
 
 
145
  except Exception as e:
146
  print(f"\n=== Error ===\n{str(e)}")
147
  messages.append(
@@ -154,10 +156,14 @@ def stream_gemini_response(message_input: str|gr.File, messages: list) -> Iterat
154
 
155
  def user_message(message_text, file_upload, history: list) -> tuple[str, None, list]:
156
  """Adds user message to chat history"""
 
 
 
157
  msg = message_text if message_text else file_upload
158
  history.append(ChatMessage(role="user", content=msg if isinstance(msg, str) else msg.name)) #Store message or filename in history.
159
  return "", None, history #clear both input fields
160
 
 
161
  # Create the Gradio interface
162
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal", secondary_hue="slate", neutral_hue="neutral")) as demo:
163
  gr.Markdown("# Gemini 2.0 Flash 'Thinking' Chatbot 💭")
 
35
  if isinstance(message_input, str):
36
  user_message = message_input
37
  print(f"\n=== New Request (Text) ===")
38
+ print(f"User message (raw): {repr(user_message)}") # Debug print raw value
39
  print(f"User message: {user_message}")
40
+ if not user_message: # Check if text message is explicitly empty (empty string "" directly)
41
+ messages.append(ChatMessage(role="assistant", content="Please provide a non-empty text message or upload a file. Empty text input is not allowed.")) # More specific message
42
  yield messages
43
  return
44
 
 
143
 
144
  print(f"\n=== Final Response ===\n{response_buffer}")
145
 
146
+
147
  except Exception as e:
148
  print(f"\n=== Error ===\n{str(e)}")
149
  messages.append(
 
156
 
157
  def user_message(message_text, file_upload, history: list) -> tuple[str, None, list]:
158
  """Adds user message to chat history"""
159
+ print(f"\n=== User Message Input Check ====") #debug
160
+ print(f"Message Text: {repr(message_text)}") #debug raw text value
161
+ print(f"File Upload: {file_upload}") #debug file upload object
162
  msg = message_text if message_text else file_upload
163
  history.append(ChatMessage(role="user", content=msg if isinstance(msg, str) else msg.name)) #Store message or filename in history.
164
  return "", None, history #clear both input fields
165
 
166
+
167
  # Create the Gradio interface
168
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal", secondary_hue="slate", neutral_hue="neutral")) as demo:
169
  gr.Markdown("# Gemini 2.0 Flash 'Thinking' Chatbot 💭")