Spaces:
Sleeping
Sleeping
File size: 1,385 Bytes
c0cf2fd | 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 | 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.")
|