import streamlit as st
import time
import google.generativeai as genai
from PIL import Image
import base64
# Configure Google Gemini API Key
genai.configure(api_key="AIzaSyC7op0zN_EESTSFhXGtzHRYImp5nhvDz-c")
# Custom CSS for advanced styling
st.markdown("""
""", unsafe_allow_html=True)
# Function to display animated text
def animated_text(text, speed=0.07):
placeholder = st.empty()
displayed_text = ""
for letter in text:
displayed_text += letter
placeholder.markdown(f'
{displayed_text} ✨
', unsafe_allow_html=True)
time.sleep(speed)
# Animated Welcome Text
animated_text("🚀 Welcome to CodeFix Pro - AI Debug & Optimize! 💡")
# Streamlit Layout
st.markdown("", unsafe_allow_html=True)
# User Input for Buggy Code
buggy_code = st.text_area("🐞 Enter your buggy code here:", height=250)
# Function to debug code
def debug_code_with_gemini(code):
prompt = f"Debug the following code and provide the corrected version:\n\n{code}"
model = genai.GenerativeModel("models/gemini-2.0-flash")
response = model.generate_content(prompt)
return response.text if response.text else "⚠️ Error in AI response."
# Function to get suggestions for improvement
def get_suggestions_with_gemini(code):
prompt = f"Suggest improvements for the following code, focusing on best practices, performance optimization, and readability:\n\n{code}"
model = genai.GenerativeModel("gemini-pro")
response = model.generate_content(prompt)
return response.text if response.text else "⚠️ No suggestions available."
# Processing user input
if buggy_code:
with st.spinner("🔍 Analyzing and fixing your code... 🛠️"):
fixed_code = debug_code_with_gemini(buggy_code)
with st.spinner("✨ Enhancing your code with best practices..."):
suggestions = get_suggestions_with_gemini(fixed_code)
# Display Debugged Code
st.markdown("", unsafe_allow_html=True)
st.code(fixed_code, language="python")
# Download button for Fixed Code
st.download_button(
label="📥 Download Corrected Code",
data=fixed_code,
file_name="corrected_code.py",
mime="text/plain"
)
# Display AI Suggestions
st.markdown("", unsafe_allow_html=True)
st.write(suggestions)