Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,26 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import google.generativeai as genai
|
| 3 |
from IPython.display import display, Markdown
|
|
|
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
system_prompt = """You are a Python code reviewer. Identify bugs and provide fixed code. you should analyze the submitted code and identify potential bugs, errors, or areas of improvement.
|
| 10 |
-
you should also provide the fixed code snippets.
|
| 11 |
"""
|
|
|
|
| 12 |
model = genai.GenerativeModel(model_name='models/gemini-2.0-flash-exp',
|
| 13 |
system_instruction=system_prompt)
|
|
|
|
| 14 |
def review_code(user_code):
|
| 15 |
response = model.generate_content(user_code)
|
| 16 |
-
return response.text
|
| 17 |
|
| 18 |
# Streamlit UI
|
| 19 |
-
st.title("📢
|
| 20 |
st.write("Enter your Python code here ...")
|
| 21 |
|
| 22 |
user_code = st.text_area("Python Code:")
|
|
@@ -25,5 +29,4 @@ if st.button("Generate") and user_code:
|
|
| 25 |
with st.spinner("Analyzing..."):
|
| 26 |
feedback = review_code(user_code)
|
| 27 |
|
| 28 |
-
|
| 29 |
-
st.markdown(feedback, unsafe_allow_html=True)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import google.generativeai as genai
|
| 3 |
from IPython.display import display, Markdown
|
| 4 |
+
import os
|
| 5 |
|
| 6 |
+
# Securely load API key from Streamlit secrets
|
| 7 |
+
api_key = st.secrets["GOOGLE_API_KEY"] # Ensure you add this key in Streamlit secrets
|
| 8 |
+
genai.configure(api_key=api_key)
|
| 9 |
|
| 10 |
+
system_prompt = """You are a Python code reviewer. Identify bugs and provide fixed code.
|
| 11 |
+
You should analyze the submitted code and identify potential bugs, errors, or areas of improvement.
|
| 12 |
+
You should also provide the fixed code snippets.
|
|
|
|
|
|
|
| 13 |
"""
|
| 14 |
+
|
| 15 |
model = genai.GenerativeModel(model_name='models/gemini-2.0-flash-exp',
|
| 16 |
system_instruction=system_prompt)
|
| 17 |
+
|
| 18 |
def review_code(user_code):
|
| 19 |
response = model.generate_content(user_code)
|
| 20 |
+
return response.text if hasattr(response, "text") else "Error: No response received."
|
| 21 |
|
| 22 |
# Streamlit UI
|
| 23 |
+
st.title("📢 AI Code Reviewer")
|
| 24 |
st.write("Enter your Python code here ...")
|
| 25 |
|
| 26 |
user_code = st.text_area("Python Code:")
|
|
|
|
| 29 |
with st.spinner("Analyzing..."):
|
| 30 |
feedback = review_code(user_code)
|
| 31 |
|
| 32 |
+
st.markdown(f"```\n{feedback}\n```") # Display response in code block
|
|
|