AI_Code_Reviewr / app.py
Saijr's picture
Update app.py
c0cf2fd verified
Raw
History Blame Contribute Delete
1.39 kB
import streamlit as st
import google.generativeai as genai
import os
# Get API Key from Hugging Face Secrets
api_key = os.getenv("GEMINI_API_KEY")
# Check if API Key is available
if not api_key:
st.error("โš ๏ธ API key not found! Please set 'GEMINI_API_KEY' in Hugging Face Secrets.")
else:
# Configure Gemini AI
genai.configure(api_key=api_key)
# Load Model
model = genai.GenerativeModel(
model_name="gemini-1.5-flash",
system_instruction="""Analyze the submitted code and identify potential bugs,
errors, or areas of improvement. Generate a Bug Report and Fixed Code only."""
)
# Streamlit UI
st.title("๐Ÿค– AI Code Reviewer")
st.write("๐Ÿ” Enter your Python code, and AI will review and fix it!")
user_code = st.text_area("Enter Your Python Code Here...", height=200)
if st.button("Generate Review"):
if user_code.strip():
st.subheader("๐Ÿ”น Code Review & Suggestions")
# AI Code Review
response = model.generate_content(user_code)
st.write(response.text) # Display AI's review
# Option to Display Code in a Better Format
st.subheader("๐Ÿ”น Fixed Code Suggestion")
st.code(response.text, language="python")
else:
st.warning("โš ๏ธ Please enter some Python code for analysis.")