Spaces:
Sleeping
Sleeping
File size: 3,173 Bytes
a7850bd ecd93f7 a7850bd fe144c6 c6f3bba 3cebf92 a7850bd ecd93f7 a7850bd ecd93f7 3cebf92 ecd93f7 a7850bd 3cebf92 ecd93f7 a7850bd 3cebf92 ecd93f7 a7850bd 3cebf92 ecd93f7 a7850bd ecd93f7 a7850bd ecd93f7 a7850bd ecd93f7 3cebf92 ecd93f7 3cebf92 ecd93f7 a7850bd 3cebf92 a7850bd ecd93f7 3cebf92 ecd93f7 3cebf92 ecd93f7 a7850bd 3cebf92 a7850bd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
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("""
<style>
body, .stApp {background-color: #F5C6C6 !important; color: #000000 !important;}
.main-title {text-align: center; font-size: 45px; font-weight: bold; color: #000000 !important;}
.sub-header {text-align: center; font-size: 28px; font-weight: bold; color: #000000 !important;}
.stTextArea textarea {background-color: #000000 !important; color: #FFFFFF !important; border-radius: 12px;}
.stButton button {background-color: #FF4500; color: white; font-size: 20px; border-radius: 12px;}
.stDownloadButton button {background-color: #32CD32; color: white; font-size: 20px; border-radius: 12px;}
</style>
""", 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'<h1 class="main-title">{displayed_text} β¨</h1>', unsafe_allow_html=True)
time.sleep(speed)
# Animated Welcome Text
animated_text("π Welcome to CodeFix Pro - AI Debug & Optimize! π‘")
# Streamlit Layout
st.markdown("<h2 class='sub-header'>π€ Smart AI-Powered Code Debugger & Enhancer</h2>", 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("<h2 class='sub-header'>β
Your Debugged Code:</h2>", 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("<h2 class='sub-header'>π‘ Smart AI Suggestions:</h2>", unsafe_allow_html=True)
st.write(suggestions)
|