trohith89 commited on
Commit
a7850bd
Β·
verified Β·
1 Parent(s): 9a25ee8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -35
app.py CHANGED
@@ -1,69 +1,76 @@
1
- import streamlit as st
2
  import time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
- # Animated text function
5
- def animated_text(text, speed=0.05):
6
  placeholder = st.empty()
7
  displayed_text = ""
8
  for letter in text:
9
  displayed_text += letter
10
- placeholder.markdown(f"""
11
- <h1 style="text-align:center; color: #FF4500;">{displayed_text} πŸš€</h1>
12
- """, unsafe_allow_html=True) # Corrected f-string formatting
13
  time.sleep(speed)
14
 
15
- # Display animated text
16
- animated_text("Welcome to GenAI App - AI Code Reviewer!", speed=0.1)
17
-
18
- import google.generativeai as genai
19
-
20
- # Set up Google Gemini API Key
21
- genai.configure(api_key="AIzaSyC7op0zN_EESTSFhXGtzHRYImp5nhvDz-c")
22
 
23
- # Streamlit App Title
24
- st.title("πŸ€– AI-Powered Code Debugging")
25
 
26
- # Text Area for User Input (Buggy Code)
27
- buggy_code = st.text_area("🐞 Enter your buggy code here:", height=200)
28
 
29
- # Function to Debug Code Using Gemini AI
30
  def debug_code_with_gemini(code):
31
  prompt = f"Debug the following code and provide the corrected version:\n\n{code}"
32
-
33
  model = genai.GenerativeModel("models/gemini-2.0-flash")
34
  response = model.generate_content(prompt)
35
-
36
  return response.text if response.text else "⚠️ Error in AI response."
37
 
38
- # Function to Generate Code Improvement Suggestions
39
  def get_suggestions_with_gemini(code):
40
  prompt = f"Suggest improvements for the following code, focusing on best practices, performance optimization, and readability:\n\n{code}"
41
-
42
  model = genai.GenerativeModel("gemini-pro")
43
  response = model.generate_content(prompt)
44
-
45
  return response.text if response.text else "⚠️ No suggestions available."
46
 
47
- # Process Code When Input is Given
48
  if buggy_code:
49
  with st.spinner("πŸ› οΈ Debugging your code..."):
50
  fixed_code = debug_code_with_gemini(buggy_code)
51
 
52
- with st.spinner("πŸ” Generating suggestions..."):
53
  suggestions = get_suggestions_with_gemini(fixed_code)
54
 
55
- # Display Fixed Code
56
- st.subheader("βœ… Fixed Code:")
57
- st.code(fixed_code, language="python") # Adjust language if needed
58
-
59
- # Copy Button for Fixed Code
60
  st.download_button(
61
- label="πŸ“‹ Copy Fixed Code",
62
  data=fixed_code,
63
  file_name="fixed_code.py",
64
  mime="text/plain"
65
  )
66
-
67
- # Display AI-Generated Suggestions
68
- st.subheader("πŸ’‘ Suggestions for Improvement:")
69
- st.write(suggestions)
 
1
+ import streamlit as st
2
  import time
3
+ import google.generativeai as genai
4
+ from PIL import Image
5
+ import base64
6
+
7
+ # Configure Google Gemini API Key
8
+ genai.configure(api_key="AIzaSyC7op0zN_EESTSFhXGtzHRYImp5nhvDz-c")
9
+
10
+ # Custom CSS for advanced styling
11
+ st.markdown("""
12
+ <style>
13
+ body {background-color: #0E0E0E; color: #FFFFFF;}
14
+ .main-title {text-align: center; font-size: 40px; font-weight: bold; color: #FFA500;}
15
+ .sub-header {text-align: center; font-size: 25px; font-weight: bold; color: #FFD700;}
16
+ .stTextArea textarea {background-color: #222; color: #FFA500; border-radius: 10px;}
17
+ .stButton button {background-color: #FF4500; color: white; font-size: 18px; border-radius: 10px;}
18
+ .stDownloadButton button {background-color: #32CD32; color: white; font-size: 18px; border-radius: 10px;}
19
+ </style>
20
+ """, unsafe_allow_html=True)
21
 
22
+ # Function to display animated text
23
+ def animated_text(text, speed=0.07):
24
  placeholder = st.empty()
25
  displayed_text = ""
26
  for letter in text:
27
  displayed_text += letter
28
+ placeholder.markdown(f'<h1 class="main-title">{displayed_text} πŸš€</h1>', unsafe_allow_html=True)
 
 
29
  time.sleep(speed)
30
 
31
+ # Animated Welcome Text
32
+ animated_text("Welcome to AI Code Debugger & Optimizer!")
 
 
 
 
 
33
 
34
+ # Streamlit Layout
35
+ st.markdown("<h2 class='sub-header'>πŸš€ AI-Powered Code Debugging & Enhancement</h2>", unsafe_allow_html=True)
36
 
37
+ # User Input for Buggy Code
38
+ buggy_code = st.text_area("🐞 Paste your buggy code below:", height=200)
39
 
40
+ # Function to debug code
41
  def debug_code_with_gemini(code):
42
  prompt = f"Debug the following code and provide the corrected version:\n\n{code}"
 
43
  model = genai.GenerativeModel("models/gemini-2.0-flash")
44
  response = model.generate_content(prompt)
 
45
  return response.text if response.text else "⚠️ Error in AI response."
46
 
47
+ # Function to get suggestions for improvement
48
  def get_suggestions_with_gemini(code):
49
  prompt = f"Suggest improvements for the following code, focusing on best practices, performance optimization, and readability:\n\n{code}"
 
50
  model = genai.GenerativeModel("gemini-pro")
51
  response = model.generate_content(prompt)
 
52
  return response.text if response.text else "⚠️ No suggestions available."
53
 
54
+ # Processing user input
55
  if buggy_code:
56
  with st.spinner("πŸ› οΈ Debugging your code..."):
57
  fixed_code = debug_code_with_gemini(buggy_code)
58
 
59
+ with st.spinner("πŸ” Generating optimization suggestions..."):
60
  suggestions = get_suggestions_with_gemini(fixed_code)
61
 
62
+ # Display Debugged Code
63
+ st.markdown("<h2 class='sub-header'>βœ… Fixed Code:</h2>", unsafe_allow_html=True)
64
+ st.code(fixed_code, language="python")
65
+
66
+ # Download button for Fixed Code
67
  st.download_button(
68
+ label="πŸ“₯ Download Fixed Code",
69
  data=fixed_code,
70
  file_name="fixed_code.py",
71
  mime="text/plain"
72
  )
73
+
74
+ # Display AI Suggestions
75
+ st.markdown("<h2 class='sub-header'>πŸ’‘ AI-Generated Suggestions:</h2>", unsafe_allow_html=True)
76
+ st.write(suggestions)