Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,5 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import google.generativeai as genai
|
| 3 |
-
import pyperclip
|
| 4 |
-
import time
|
| 5 |
|
| 6 |
# Configure the Gemini API
|
| 7 |
genai.configure(api_key=st.secrets["GOOGLE_API_KEY"])
|
|
@@ -12,7 +10,6 @@ generation_config = {
|
|
| 12 |
"top_p": 0.95,
|
| 13 |
"top_k": 64,
|
| 14 |
"max_output_tokens": 8192,
|
| 15 |
-
"response_mime_type": "text/plain",
|
| 16 |
}
|
| 17 |
|
| 18 |
model = genai.GenerativeModel(
|
|
@@ -26,131 +23,103 @@ def generate_response(user_input):
|
|
| 26 |
response = chat_session.send_message(user_input)
|
| 27 |
return response.text
|
| 28 |
|
| 29 |
-
def copy_to_clipboard(text):
|
| 30 |
-
pyperclip.copy(text)
|
| 31 |
-
|
| 32 |
# Streamlit UI setup
|
| 33 |
-
st.set_page_config(page_title="
|
| 34 |
|
| 35 |
st.markdown("""
|
| 36 |
<style>
|
| 37 |
-
@import url('https://fonts.googleapis.com/css2?family=
|
| 38 |
|
| 39 |
body {
|
| 40 |
-
font-family: '
|
| 41 |
-
background:
|
| 42 |
-
color: #
|
| 43 |
}
|
| 44 |
.stApp {
|
| 45 |
-
max-width:
|
| 46 |
margin: 0 auto;
|
| 47 |
padding: 2rem;
|
| 48 |
}
|
| 49 |
.main-container {
|
| 50 |
-
background:
|
| 51 |
-
border-radius:
|
| 52 |
padding: 2rem;
|
| 53 |
-
box-shadow: 0
|
| 54 |
}
|
| 55 |
h1 {
|
| 56 |
font-size: 2.5rem;
|
| 57 |
font-weight: 700;
|
| 58 |
-
color: #
|
| 59 |
text-align: center;
|
| 60 |
margin-bottom: 1rem;
|
| 61 |
}
|
| 62 |
.subtitle {
|
| 63 |
-
font-size: 1.
|
| 64 |
text-align: center;
|
| 65 |
-
color: #
|
| 66 |
margin-bottom: 2rem;
|
| 67 |
}
|
| 68 |
-
.stTextArea label {
|
| 69 |
-
font-size: 1.1rem;
|
| 70 |
-
font-weight: 600;
|
| 71 |
-
color: #34495e;
|
| 72 |
-
}
|
| 73 |
.stTextArea textarea {
|
| 74 |
-
border: 2px solid #
|
| 75 |
-
border-radius:
|
| 76 |
font-size: 1rem;
|
| 77 |
-
padding: 0.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
}
|
| 79 |
.stButton button {
|
| 80 |
-
background:
|
| 81 |
color: white;
|
| 82 |
border: none;
|
| 83 |
-
border-radius:
|
| 84 |
font-size: 1.1rem;
|
| 85 |
font-weight: 600;
|
| 86 |
-
padding: 0.
|
| 87 |
transition: all 0.3s ease;
|
| 88 |
-
|
| 89 |
}
|
| 90 |
.stButton button:hover {
|
| 91 |
-
|
| 92 |
-
box-shadow: 0 6px 8px rgba(0,0,0,0.15);
|
| 93 |
}
|
| 94 |
.output-container {
|
| 95 |
-
background: #
|
| 96 |
-
border-radius:
|
| 97 |
padding: 1rem;
|
| 98 |
margin-top: 2rem;
|
| 99 |
}
|
| 100 |
.code-block {
|
| 101 |
-
background-color: #
|
| 102 |
-
color: #
|
| 103 |
font-family: 'Fira Code', monospace;
|
| 104 |
font-size: 0.9rem;
|
| 105 |
-
border-radius:
|
| 106 |
padding: 1rem;
|
| 107 |
margin-top: 1rem;
|
| 108 |
-
|
| 109 |
-
}
|
| 110 |
-
.copy-btn {
|
| 111 |
-
position: absolute;
|
| 112 |
-
top: 0.5rem;
|
| 113 |
-
right: 0.5rem;
|
| 114 |
-
background: rgba(255, 255, 255, 0.1);
|
| 115 |
-
color: #abb2bf;
|
| 116 |
-
border: none;
|
| 117 |
-
border-radius: 5px;
|
| 118 |
-
padding: 0.2rem 0.5rem;
|
| 119 |
-
font-size: 0.8rem;
|
| 120 |
-
cursor: pointer;
|
| 121 |
-
transition: all 0.2s ease;
|
| 122 |
-
}
|
| 123 |
-
.copy-btn:hover {
|
| 124 |
-
background: rgba(255, 255, 255, 0.2);
|
| 125 |
}
|
| 126 |
.stAlert {
|
| 127 |
-
background-color: #
|
| 128 |
-
color: #
|
| 129 |
-
border-radius:
|
| 130 |
border: none;
|
| 131 |
-
padding: 0.
|
| 132 |
}
|
| 133 |
.stSpinner {
|
| 134 |
-
color: #
|
| 135 |
}
|
| 136 |
</style>
|
| 137 |
""", unsafe_allow_html=True)
|
| 138 |
|
| 139 |
st.markdown('<div class="main-container">', unsafe_allow_html=True)
|
| 140 |
-
st.title("
|
| 141 |
st.markdown('<p class="subtitle">Powered by Google Gemini</p>', unsafe_allow_html=True)
|
| 142 |
|
| 143 |
-
prompt = st.text_area("What code can I help you with today?", height=
|
| 144 |
-
|
| 145 |
-
col1, col2 = st.columns([1, 1])
|
| 146 |
-
|
| 147 |
-
with col1:
|
| 148 |
-
generate_button = st.button("Generate Code")
|
| 149 |
-
|
| 150 |
-
with col2:
|
| 151 |
-
language = st.selectbox("Select language", ["Python", "JavaScript", "Java", "C++", "Ruby"])
|
| 152 |
|
| 153 |
-
if
|
| 154 |
if prompt.strip() == "":
|
| 155 |
st.error("Please enter a valid prompt.")
|
| 156 |
else:
|
|
@@ -160,19 +129,15 @@ if generate_button:
|
|
| 160 |
|
| 161 |
st.markdown('<div class="output-container">', unsafe_allow_html=True)
|
| 162 |
code_blocks = completed_text.split("\n\n")
|
| 163 |
-
for
|
| 164 |
-
st.markdown(
|
| 165 |
-
st.code(block
|
| 166 |
-
copy_button = st.button(f"Copy Code Block {i+1}", key=f"copy_{i}")
|
| 167 |
-
if copy_button:
|
| 168 |
-
copy_to_clipboard(block)
|
| 169 |
-
st.success(f"Code block {i+1} copied to clipboard!")
|
| 170 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 171 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 172 |
|
| 173 |
st.markdown("""
|
| 174 |
-
<div style='text-align: center; margin-top: 2rem; color: #
|
| 175 |
-
Created with ❤️ by Your
|
| 176 |
</div>
|
| 177 |
""", unsafe_allow_html=True)
|
| 178 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import google.generativeai as genai
|
|
|
|
|
|
|
| 3 |
|
| 4 |
# Configure the Gemini API
|
| 5 |
genai.configure(api_key=st.secrets["GOOGLE_API_KEY"])
|
|
|
|
| 10 |
"top_p": 0.95,
|
| 11 |
"top_k": 64,
|
| 12 |
"max_output_tokens": 8192,
|
|
|
|
| 13 |
}
|
| 14 |
|
| 15 |
model = genai.GenerativeModel(
|
|
|
|
| 23 |
response = chat_session.send_message(user_input)
|
| 24 |
return response.text
|
| 25 |
|
|
|
|
|
|
|
|
|
|
| 26 |
# Streamlit UI setup
|
| 27 |
+
st.set_page_config(page_title="Sleek AI Code Assistant", page_icon="💻", layout="wide")
|
| 28 |
|
| 29 |
st.markdown("""
|
| 30 |
<style>
|
| 31 |
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap');
|
| 32 |
|
| 33 |
body {
|
| 34 |
+
font-family: 'Inter', sans-serif;
|
| 35 |
+
background-color: #f0f4f8;
|
| 36 |
+
color: #1a202c;
|
| 37 |
}
|
| 38 |
.stApp {
|
| 39 |
+
max-width: 1000px;
|
| 40 |
margin: 0 auto;
|
| 41 |
padding: 2rem;
|
| 42 |
}
|
| 43 |
.main-container {
|
| 44 |
+
background: #ffffff;
|
| 45 |
+
border-radius: 16px;
|
| 46 |
padding: 2rem;
|
| 47 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
|
| 48 |
}
|
| 49 |
h1 {
|
| 50 |
font-size: 2.5rem;
|
| 51 |
font-weight: 700;
|
| 52 |
+
color: #2d3748;
|
| 53 |
text-align: center;
|
| 54 |
margin-bottom: 1rem;
|
| 55 |
}
|
| 56 |
.subtitle {
|
| 57 |
+
font-size: 1.1rem;
|
| 58 |
text-align: center;
|
| 59 |
+
color: #4a5568;
|
| 60 |
margin-bottom: 2rem;
|
| 61 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
.stTextArea textarea {
|
| 63 |
+
border: 2px solid #e2e8f0;
|
| 64 |
+
border-radius: 8px;
|
| 65 |
font-size: 1rem;
|
| 66 |
+
padding: 0.75rem;
|
| 67 |
+
transition: all 0.3s ease;
|
| 68 |
+
}
|
| 69 |
+
.stTextArea textarea:focus {
|
| 70 |
+
border-color: #4299e1;
|
| 71 |
+
box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.5);
|
| 72 |
}
|
| 73 |
.stButton button {
|
| 74 |
+
background-color: #4299e1;
|
| 75 |
color: white;
|
| 76 |
border: none;
|
| 77 |
+
border-radius: 8px;
|
| 78 |
font-size: 1.1rem;
|
| 79 |
font-weight: 600;
|
| 80 |
+
padding: 0.75rem 2rem;
|
| 81 |
transition: all 0.3s ease;
|
| 82 |
+
width: 100%;
|
| 83 |
}
|
| 84 |
.stButton button:hover {
|
| 85 |
+
background-color: #3182ce;
|
|
|
|
| 86 |
}
|
| 87 |
.output-container {
|
| 88 |
+
background: #f7fafc;
|
| 89 |
+
border-radius: 8px;
|
| 90 |
padding: 1rem;
|
| 91 |
margin-top: 2rem;
|
| 92 |
}
|
| 93 |
.code-block {
|
| 94 |
+
background-color: #2d3748;
|
| 95 |
+
color: #e2e8f0;
|
| 96 |
font-family: 'Fira Code', monospace;
|
| 97 |
font-size: 0.9rem;
|
| 98 |
+
border-radius: 8px;
|
| 99 |
padding: 1rem;
|
| 100 |
margin-top: 1rem;
|
| 101 |
+
overflow-x: auto;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
}
|
| 103 |
.stAlert {
|
| 104 |
+
background-color: #ebf8ff;
|
| 105 |
+
color: #2b6cb0;
|
| 106 |
+
border-radius: 8px;
|
| 107 |
border: none;
|
| 108 |
+
padding: 0.75rem 1rem;
|
| 109 |
}
|
| 110 |
.stSpinner {
|
| 111 |
+
color: #4299e1;
|
| 112 |
}
|
| 113 |
</style>
|
| 114 |
""", unsafe_allow_html=True)
|
| 115 |
|
| 116 |
st.markdown('<div class="main-container">', unsafe_allow_html=True)
|
| 117 |
+
st.title("💻 Sleek AI Code Assistant")
|
| 118 |
st.markdown('<p class="subtitle">Powered by Google Gemini</p>', unsafe_allow_html=True)
|
| 119 |
|
| 120 |
+
prompt = st.text_area("What code can I help you with today?", height=120)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
+
if st.button("Generate Code"):
|
| 123 |
if prompt.strip() == "":
|
| 124 |
st.error("Please enter a valid prompt.")
|
| 125 |
else:
|
|
|
|
| 129 |
|
| 130 |
st.markdown('<div class="output-container">', unsafe_allow_html=True)
|
| 131 |
code_blocks = completed_text.split("\n\n")
|
| 132 |
+
for block in code_blocks:
|
| 133 |
+
st.markdown('<div class="code-block">', unsafe_allow_html=True)
|
| 134 |
+
st.code(block)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 136 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 137 |
|
| 138 |
st.markdown("""
|
| 139 |
+
<div style='text-align: center; margin-top: 2rem; color: #4a5568;'>
|
| 140 |
+
Created with ❤️ by Your Sleek AI Code Assistant
|
| 141 |
</div>
|
| 142 |
""", unsafe_allow_html=True)
|
| 143 |
|