BobyMaurya455 commited on
Commit
860ac3b
·
verified ·
1 Parent(s): 4702e1c

Upload app.py

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