Saijr commited on
Commit
c0cf2fd
·
verified ·
1 Parent(s): 38aa021

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py CHANGED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import google.generativeai as genai
3
+ import os
4
+
5
+ # Get API Key from Hugging Face Secrets
6
+ api_key = os.getenv("GEMINI_API_KEY")
7
+
8
+ # Check if API Key is available
9
+ if not api_key:
10
+ st.error("⚠️ API key not found! Please set 'GEMINI_API_KEY' in Hugging Face Secrets.")
11
+ else:
12
+ # Configure Gemini AI
13
+ genai.configure(api_key=api_key)
14
+
15
+ # Load Model
16
+ model = genai.GenerativeModel(
17
+ model_name="gemini-1.5-flash",
18
+ system_instruction="""Analyze the submitted code and identify potential bugs,
19
+ errors, or areas of improvement. Generate a Bug Report and Fixed Code only."""
20
+ )
21
+
22
+ # Streamlit UI
23
+ st.title("🤖 AI Code Reviewer")
24
+ st.write("🔍 Enter your Python code, and AI will review and fix it!")
25
+
26
+ user_code = st.text_area("Enter Your Python Code Here...", height=200)
27
+
28
+ if st.button("Generate Review"):
29
+ if user_code.strip():
30
+ st.subheader("🔹 Code Review & Suggestions")
31
+
32
+ # AI Code Review
33
+ response = model.generate_content(user_code)
34
+ st.write(response.text) # Display AI's review
35
+
36
+ # Option to Display Code in a Better Format
37
+ st.subheader("🔹 Fixed Code Suggestion")
38
+ st.code(response.text, language="python")
39
+
40
+ else:
41
+ st.warning("⚠️ Please enter some Python code for analysis.")