| |
|
| |
|
| | import streamlit as st
|
| | import google.generativeai as genai
|
| |
|
| |
|
| | genai.configure(api_key="AIzaSyB2FrTywdRUmHXICxRPYTN_TznajASTKDY")
|
| | model = genai.GenerativeModel("gemini-1.5-flash")
|
| |
|
| |
|
| | st.title("AI-Powered Python Code Assistant")
|
| | st.markdown("This assistant can help you with code suggestions, debugging, and reusable snippets using Gemini AI.")
|
| |
|
| |
|
| | st.sidebar.header("Select Feature")
|
| | feature = st.sidebar.selectbox(
|
| | "Choose what you need help with:",
|
| | ["Code Suggestions", "Code Debugging", "Reusable Code Snippets", "General Code Query"]
|
| | )
|
| |
|
| |
|
| | user_input = st.text_area("Enter your Python code or query here:")
|
| |
|
| |
|
| | if st.button("Get AI Suggestions"):
|
| |
|
| |
|
| | if feature == "Code Suggestions":
|
| | prompt = f"Suggest code completion for the following Python code:\n{user_input}"
|
| | elif feature == "Code Debugging":
|
| | prompt = f"Find and fix the bugs in the following Python code:\n{user_input}"
|
| | elif feature == "Reusable Code Snippets":
|
| | prompt = f"Provide reusable Python code snippets related to: {user_input}"
|
| | else:
|
| | prompt = f"Provide an explanation or advice on this Python code/query:\n{user_input}"
|
| |
|
| |
|
| | response = model.generate_content(prompt)
|
| |
|
| |
|
| | st.subheader("AI's Response:")
|
| | st.code(response.text, language="python")
|
| |
|
| |
|
| | st.markdown("---")
|
| | st.markdown("Powered by **Streamlit** and **Google Gemini AI**")
|
| |
|