kaitongg commited on
Commit
11f6ebb
·
verified ·
1 Parent(s): d32ad80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -42
app.py CHANGED
@@ -261,7 +261,6 @@ def generate_feedback_from_prompt(prompt_input: str) -> str:
261
 
262
  try:
263
  print("Generating feedback with Gemini...")
264
- print(f"Prompt length: {len(prompt_input)} characters")
265
 
266
  # Extract just the user's input text
267
  user_text = prompt_input
@@ -270,70 +269,43 @@ def generate_feedback_from_prompt(prompt_input: str) -> str:
270
  if len(parts) > 1:
271
  user_text = parts[1].strip().strip('"')
272
 
273
- # Simplified prompt
274
- simple_prompt = f"""Provide educational feedback on this architectural description in 250-300 words:
275
-
276
- {user_text}
277
-
278
- Be helpful and constructive."""
279
-
280
- print(f"Simplified prompt length: {len(simple_prompt)} characters")
281
-
282
- generation_config = {
283
- 'temperature': 0.7,
284
- 'max_output_tokens': 600,
285
- 'top_p': 0.95,
286
- }
287
 
288
- response = gemini_model.generate_content(
289
- simple_prompt,
290
- generation_config=generation_config
291
- )
292
 
293
- print(f"Response received. Candidates: {len(response.candidates) if response.candidates else 0}")
 
294
 
295
- if response.candidates:
296
- candidate = response.candidates[0]
297
- print(f"Finish reason: {candidate.finish_reason}")
298
- print(f"Has content: {candidate.content is not None}")
299
- if candidate.content:
300
- print(f"Parts count: {len(candidate.content.parts) if candidate.content.parts else 0}")
301
- if candidate.safety_ratings:
302
- ratings_info = [(r.category, r.probability) for r in candidate.safety_ratings]
303
- print(f"Safety ratings: {ratings_info}")
304
 
305
  # Extract text
306
  llm_response_text = None
307
 
308
  try:
309
  llm_response_text = response.text
310
- print("✓ Got text from response.text")
311
  except Exception as e:
312
- print(f"Failed to get response.text: {e}")
313
 
 
314
  if response.candidates and response.candidates[0].content:
315
  candidate = response.candidates[0]
316
  if candidate.content.parts:
317
  texts = [part.text for part in candidate.content.parts if hasattr(part, 'text')]
318
  if texts:
319
  llm_response_text = "".join(texts)
320
- print("✓ Got text from candidate parts")
321
 
322
  if not llm_response_text:
323
- if response.candidates:
324
- finish_reason = response.candidates[0].finish_reason
325
- if finish_reason == 2:
326
- return "⚠️ Content blocked by safety filter. This may be due to API restrictions. Try:\n1. Using simpler, more direct language\n2. Avoiding technical jargon\n3. Shortening your description"
327
- return "⚠️ No response generated. Please try again with simpler input."
328
 
329
- llm_response_text = llm_response_text.strip()
330
- print(f"✓ Feedback generated ({len(llm_response_text)} chars)")
331
- return llm_response_text
332
 
333
  except Exception as e:
334
  error_msg = str(e)
335
- print(f"❌ Full error: {error_msg}")
336
- return f"Error: {error_msg}"
337
 
338
  # ============================================
339
  # 9. GRADIO INTERFACE
 
261
 
262
  try:
263
  print("Generating feedback with Gemini...")
 
264
 
265
  # Extract just the user's input text
266
  user_text = prompt_input
 
269
  if len(parts) > 1:
270
  user_text = parts[1].strip().strip('"')
271
 
272
+ # Ultra-simplified prompt - just the core request
273
+ simple_prompt = f"Provide brief educational feedback on this architectural description: {user_text}"
 
 
 
 
 
 
 
 
 
 
 
 
274
 
275
+ print(f"Sending prompt ({len(simple_prompt)} chars)")
 
 
 
276
 
277
+ # Minimal configuration - only what's absolutely necessary
278
+ response = gemini_model.generate_content(simple_prompt)
279
 
280
+ print(f"Response received")
 
 
 
 
 
 
 
 
281
 
282
  # Extract text
283
  llm_response_text = None
284
 
285
  try:
286
  llm_response_text = response.text
287
+ print(f"✓ Got text ({len(llm_response_text)} chars)")
288
  except Exception as e:
289
+ print(f"Failed to get text: {str(e)[:100]}")
290
 
291
+ # Try alternative extraction
292
  if response.candidates and response.candidates[0].content:
293
  candidate = response.candidates[0]
294
  if candidate.content.parts:
295
  texts = [part.text for part in candidate.content.parts if hasattr(part, 'text')]
296
  if texts:
297
  llm_response_text = "".join(texts)
298
+ print(f"✓ Got text from parts ({len(llm_response_text)} chars)")
299
 
300
  if not llm_response_text:
301
+ return "⚠️ No response generated. This may be an API limitation. Try:\n- Shorter, simpler descriptions\n- Removing technical terms\n- Testing with basic input like 'large windows'"
 
 
 
 
302
 
303
+ return llm_response_text.strip()
 
 
304
 
305
  except Exception as e:
306
  error_msg = str(e)
307
+ print(f"Error: {error_msg[:200]}")
308
+ return f"Error: {error_msg}"
309
 
310
  # ============================================
311
  # 9. GRADIO INTERFACE