Update app.py
Browse files
app.py
CHANGED
@@ -1,46 +1,48 @@
|
|
1 |
-
#genai.configure(api_key="AIzaSyB2FrTywdRUmHXICxRPYTN_TznajASTKDY")
|
2 |
-
|
3 |
-
import streamlit as st
|
4 |
-
import google.generativeai as genai
|
5 |
-
|
6 |
-
# Configure the API key for Gemini AI
|
7 |
-
genai.configure(api_key="
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
prompt = f"
|
32 |
-
elif feature == "
|
33 |
-
prompt = f"
|
34 |
-
|
35 |
-
prompt = f"Provide
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
1 |
+
#genai.configure(api_key="AIzaSyB2FrTywdRUmHXICxRPYTN_TznajASTKDY")
|
2 |
+
|
3 |
+
import streamlit as st
|
4 |
+
import google.generativeai as genai
|
5 |
+
|
6 |
+
# Configure the API key for Gemini AI
|
7 |
+
genai.configure(api_key="AIzaSyD8tAz466UNCkLl83WBT05imim-JYL5Gr4")
|
8 |
+
|
9 |
+
# AIzaSyB2FrTywdRUmHXICxRPYTN_TznajASTKDY
|
10 |
+
model = genai.GenerativeModel("gemini-1.5-flash")
|
11 |
+
|
12 |
+
# Streamlit App layout
|
13 |
+
st.title("AI-Powered Python Code Assistant")
|
14 |
+
st.markdown("This assistant can help you with code suggestions, debugging, and reusable snippets using Gemini AI.")
|
15 |
+
|
16 |
+
# Sidebar
|
17 |
+
st.sidebar.header("Select Feature")
|
18 |
+
feature = st.sidebar.selectbox(
|
19 |
+
"Choose what you need help with:",
|
20 |
+
["Code Suggestions", "Code Debugging", "Reusable Code Snippets", "General Code Query"]
|
21 |
+
)
|
22 |
+
|
23 |
+
# Input box for user to type code or query
|
24 |
+
user_input = st.text_area("Enter your Python code or query here:")
|
25 |
+
|
26 |
+
# Button to trigger the AI response
|
27 |
+
if st.button("Get AI Suggestions"):
|
28 |
+
|
29 |
+
# Generate response based on selected feature
|
30 |
+
if feature == "Code Suggestions":
|
31 |
+
prompt = f"Suggest code completion for the following Python code:\n{user_input}"
|
32 |
+
elif feature == "Code Debugging":
|
33 |
+
prompt = f"Find and fix the bugs in the following Python code:\n{user_input}"
|
34 |
+
elif feature == "Reusable Code Snippets":
|
35 |
+
prompt = f"Provide reusable Python code snippets related to: {user_input}"
|
36 |
+
else:
|
37 |
+
prompt = f"Provide an explanation or advice on this Python code/query:\n{user_input}"
|
38 |
+
|
39 |
+
# Get response from Gemini AI model
|
40 |
+
response = model.generate_content(prompt)
|
41 |
+
|
42 |
+
# Display AI's response in the app
|
43 |
+
st.subheader("AI's Response:")
|
44 |
+
st.code(response.text, language="python")
|
45 |
+
|
46 |
+
# Optionally, you can add a footer or additional features here
|
47 |
+
st.markdown("---")
|
48 |
+
st.markdown("Powered by **Streamlit** and **Google Gemini AI**")
|