Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,56 +6,49 @@ from google import genai
|
|
| 6 |
# Initialize Gemini Client with API key from environment
|
| 7 |
client = genai.Client(api_key=os.environ.get("GEMINI_API_KEY"))
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
}
|
| 18 |
-
}
|
| 19 |
|
| 20 |
# Main App
|
| 21 |
def main():
|
| 22 |
-
st.set_page_config(page_title="
|
| 23 |
-
st.title("
|
| 24 |
-
st.write("Upload
|
| 25 |
-
"
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
)
|
| 47 |
-
},
|
| 48 |
-
image_data
|
| 49 |
-
]
|
| 50 |
|
| 51 |
response = client.models.generate_content(
|
| 52 |
model="gemini-2.5-flash",
|
| 53 |
-
contents=
|
| 54 |
-
config={"tools": [{"google_search": {}}]}
|
| 55 |
)
|
| 56 |
|
| 57 |
-
st.success("
|
| 58 |
st.markdown(response.text)
|
| 59 |
|
| 60 |
if __name__ == "__main__":
|
| 61 |
-
main()
|
|
|
|
| 6 |
# Initialize Gemini Client with API key from environment
|
| 7 |
client = genai.Client(api_key=os.environ.get("GEMINI_API_KEY"))
|
| 8 |
|
| 9 |
+
# Supported file types
|
| 10 |
+
SUPPORTED_EXTENSIONS = ["py", "c", "cpp", "java", "js", "jsx"]
|
| 11 |
+
|
| 12 |
+
# Helper: Read and decode code file
|
| 13 |
+
def read_code_file(file):
|
| 14 |
+
content = file.read().decode("utf-8")
|
| 15 |
+
filename = file.name
|
| 16 |
+
return filename, content
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Main App
|
| 19 |
def main():
|
| 20 |
+
st.set_page_config(page_title="🧠 Code Analyzer & Fixer", layout="centered")
|
| 21 |
+
st.title("🛠️ Code Analyzer & Bug Fixer")
|
| 22 |
+
st.write("Upload a code file (Python, C, C++, Java, or React) and get a detailed analysis including:\n"
|
| 23 |
+
"- README-style description\n"
|
| 24 |
+
"- Bug detection\n"
|
| 25 |
+
"- Corrected code\n"
|
| 26 |
+
"- Summary of changes")
|
| 27 |
+
|
| 28 |
+
uploaded_file = st.file_uploader("Upload your code file", type=SUPPORTED_EXTENSIONS)
|
| 29 |
+
|
| 30 |
+
if uploaded_file:
|
| 31 |
+
filename, code_text = read_code_file(uploaded_file)
|
| 32 |
+
st.code(code_text, language=filename.split(".")[-1])
|
| 33 |
+
|
| 34 |
+
if st.button("🔍 Analyze and Fix Code"):
|
| 35 |
+
with st.spinner("Analyzing your code using Gemini..."):
|
| 36 |
+
prompt = (
|
| 37 |
+
f"You are a software code analysis assistant. Given the code below, perform the following tasks:\n\n"
|
| 38 |
+
f"1. Provide a short README-style summary of what the code is intended to do.\n"
|
| 39 |
+
f"2. Identify any bugs or issues in the code.\n"
|
| 40 |
+
f"3. Provide a corrected, clean version of the entire code.\n"
|
| 41 |
+
f"4. List the changes you made in bullet points.\n\n"
|
| 42 |
+
f"--- CODE START ---\n{code_text}\n--- CODE END ---"
|
| 43 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
response = client.models.generate_content(
|
| 46 |
model="gemini-2.5-flash",
|
| 47 |
+
contents=[{"text": prompt}]
|
|
|
|
| 48 |
)
|
| 49 |
|
| 50 |
+
st.success("✅ Analysis Complete:")
|
| 51 |
st.markdown(response.text)
|
| 52 |
|
| 53 |
if __name__ == "__main__":
|
| 54 |
+
main()
|