File size: 3,795 Bytes
f8dbf90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83ac817
f8dbf90
 
 
 
 
 
 
 
 
 
 
 
d35faf8
 
 
f8dbf90
d35faf8
 
f8dbf90
d35faf8
 
 
 
 
 
 
 
 
 
 
 
 
 
f8dbf90
 
 
d35faf8
 
 
 
 
 
 
 
 
 
f8dbf90
 
d35faf8
f8dbf90
d35faf8
 
f8dbf90
d35faf8
 
83ac817
d35faf8
f8dbf90
 
83ac817
d35faf8
f8dbf90
258dc70
d35faf8
258dc70
d35faf8
258dc70
d35faf8
 
 
f8dbf90
d35faf8
 
 
 
 
 
 
 
83ac817
f8dbf90
83ac817
 
 
d35faf8
83ac817
d35faf8
83ac817
d35faf8
 
 
83ac817
d35faf8
 
 
 
 
 
 
 
83ac817
d35faf8
 
 
 
 
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import streamlit as st
import google.generativeai as genai
import requests

# Configure the Gemini API
genai.configure(api_key=st.secrets["GOOGLE_API_KEY"])

# Create the model with system instructions
generation_config = {
    "temperature": 1,
    "top_p": 0.95,
    "top_k": 64,
    "max_output_tokens": 8192,
    "response_mime_type": "text/plain",
}

model = genai.GenerativeModel(
    model_name="gemini-1.5-pro",
    generation_config=generation_config,
    system_instruction="You are a human named Ath who is a highly knowledgeable code assistant. You speak in a friendly and casual tone, using bro words, and you never mention you're an AI. Your responses should contain code only, without explanations.",
)
chat_session = model.start_chat(history=[])

def generate_response(user_input):
    response = chat_session.send_message(user_input)
    return response.text

# Streamlit UI setup
st.set_page_config(page_title="AI Code Assistant", page_icon="🤖", layout="wide")

st.markdown("""
<style>
    @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap');
    
    body {
        font-family: 'Roboto', sans-serif;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: #ffffff;
    }
    .stApp {
        max-width: 1000px;
        margin: 0 auto;
        padding: 2rem;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 20px;
        backdrop-filter: blur(10px);
    }
    h1 {
        font-size: 3rem;
        font-weight: 700;
        text-align: center;
        margin-bottom: 2rem;
        text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
    }
    .stTextArea label {
        font-size: 1.2rem;
        font-weight: 500;
        color: #ffffff;
    }
    .stTextArea textarea {
        background: rgba(255, 255, 255, 0.2);
        border: none;
        border-radius: 10px;
        color: #ffffff;
        font-size: 1rem;
        padding: 1rem;
    }
    .stButton button {
        background: linear-gradient(45deg, #FF6B6B, #4ECDC4);
        color: white;
        border: none;
        border-radius: 30px;
        font-size: 1.1rem;
        font-weight: 600;
        padding: 0.7rem 2rem;
        transition: all 0.3s ease;
        box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    }
    .stButton button:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 8px rgba(0,0,0,0.15);
    }
    .stCodeBlock {
        background-color: rgba(0, 0, 0, 0.6);
        color: #f8f8f2;
        font-size: 0.9rem;
        border-radius: 10px;
        padding: 1rem;
        margin-top: 1rem;
        overflow-x: auto;
    }
    .stAlert {
        background-color: rgba(255, 255, 255, 0.2);
        color: #ffffff;
        border-radius: 10px;
        border: none;
    }
    .stSpinner {
        color: #ffffff;
    }
</style>
""", unsafe_allow_html=True)

st.title("🤖 AI Code Assistant")
st.markdown("<h3 style='text-align: center; color: #ffffff;'>Powered by Google Gemini</h3>", unsafe_allow_html=True)

prompt = st.text_area("Enter your coding question or request:", height=150)

if st.button("Generate Code"):
    if prompt.strip() == "":
        st.error("Please enter a valid prompt.")
    else:
        with st.spinner("Generating code..."):
            completed_text = generate_response(prompt)
            st.success("Code generated successfully!")
            
            # Split the response into separate code blocks based on a custom delimiter
            code_blocks = completed_text.split("\n\n")
            for block in code_blocks:
                st.code(block, language="python")

st.markdown("""
<div style='text-align: center; margin-top: 2rem; color: rgba(255,255,255,0.7);'>
    Created with ❤️ by Your AGI Code Assistant
</div>
""", unsafe_allow_html=True)