File size: 1,802 Bytes
3403463
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#genai.configure(api_key="AIzaSyB2FrTywdRUmHXICxRPYTN_TznajASTKDY")

import streamlit as st
import google.generativeai as genai

# Configure the API key for Gemini AI
genai.configure(api_key="AIzaSyD8tAz466UNCkLl83WBT05imim-JYL5Gr4")

# AIzaSyB2FrTywdRUmHXICxRPYTN_TznajASTKDY
model = genai.GenerativeModel("gemini-1.5-flash")

# Streamlit App layout
st.title("AI-Powered Python Code Assistant")
st.markdown("This assistant can help you with code suggestions, debugging, and reusable snippets using Gemini AI.")

# Sidebar
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"]
)

# Input box for user to type code or query
user_input = st.text_area("Enter your Python code or query here:")

# Button to trigger the AI response
if st.button("Get AI Suggestions"):

    # Generate response based on selected feature
    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}"

    # Get response from Gemini AI model
    response = model.generate_content(prompt)
    
    # Display AI's response in the app
    st.subheader("AI's Response:")
    st.code(response.text, language="python")

# Optionally, you can add a footer or additional features here
st.markdown("---")
st.markdown("Powered by **Streamlit** and **Google Gemini AI**")