Spaces:
Sleeping
Sleeping
| 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.") | |