Phaneendrabayi commited on
Commit
21668e2
·
verified ·
1 Parent(s): 84b9456

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -28,21 +28,28 @@ def review_code(user_code):
28
  # Validate Python syntax
29
  compile(user_code, '<string>', 'exec')
30
 
31
- # Generate AI response
32
- response = model.generate_content(user_code)
33
 
34
- # Handle response
35
  if hasattr(response, "text"):
36
- return response.text.strip()
37
  elif hasattr(response, "candidates") and isinstance(response.candidates, list) and len(response.candidates) > 0:
38
- return response.candidates[0].text.strip()
39
  else:
40
- return "❌ Error: Unexpected response format."
 
 
 
41
  except SyntaxError as e:
42
- st.warning(f"⚠️ Invalid Python code: {e}")
 
 
43
  return None
44
  except Exception as e:
45
- st.error("🚨 An error occurred during code review.")
 
 
46
  st.exception(e)
47
  return None
48
 
 
28
  # Validate Python syntax
29
  compile(user_code, '<string>', 'exec')
30
 
31
+ # Generate AI response (Placeholder for Gemini AI)
32
+ response = model.generate_content(user_code) # Replace 'model' with actual AI integration
33
 
34
+ # Handle response and display it using IPython Markdown
35
  if hasattr(response, "text"):
36
+ output = response.text.strip()
37
  elif hasattr(response, "candidates") and isinstance(response.candidates, list) and len(response.candidates) > 0:
38
+ output = response.candidates[0].text.strip()
39
  else:
40
+ output = "❌ Error: Unexpected response format."
41
+
42
+ display(Markdown(f"### Code Review Result:\n\n{output}"))
43
+ return output
44
  except SyntaxError as e:
45
+ warning_message = f"⚠️ **Invalid Python code:** {e}"
46
+ display(Markdown(warning_message))
47
+ st.warning(warning_message)
48
  return None
49
  except Exception as e:
50
+ error_message = "🚨 **An error occurred during code review.**"
51
+ display(Markdown(error_message))
52
+ st.error(error_message)
53
  st.exception(e)
54
  return None
55