Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import google.generativeai as genai
|
| 3 |
-
import
|
|
|
|
| 4 |
|
| 5 |
# Configure the Gemini API
|
| 6 |
genai.configure(api_key=st.secrets["GOOGLE_API_KEY"])
|
|
@@ -25,48 +26,58 @@ def generate_response(user_input):
|
|
| 25 |
response = chat_session.send_message(user_input)
|
| 26 |
return response.text
|
| 27 |
|
|
|
|
|
|
|
|
|
|
| 28 |
# Streamlit UI setup
|
| 29 |
-
st.set_page_config(page_title="AI Code Assistant", page_icon="
|
| 30 |
|
| 31 |
st.markdown("""
|
| 32 |
<style>
|
| 33 |
-
@import url('https://fonts.googleapis.com/css2?family=
|
| 34 |
|
| 35 |
body {
|
| 36 |
-
font-family: '
|
| 37 |
-
background: linear-gradient(
|
| 38 |
-
color: #
|
| 39 |
}
|
| 40 |
.stApp {
|
| 41 |
-
max-width:
|
| 42 |
margin: 0 auto;
|
| 43 |
padding: 2rem;
|
| 44 |
-
|
|
|
|
|
|
|
| 45 |
border-radius: 20px;
|
| 46 |
-
|
|
|
|
| 47 |
}
|
| 48 |
h1 {
|
| 49 |
-
font-size:
|
| 50 |
font-weight: 700;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
text-align: center;
|
|
|
|
| 52 |
margin-bottom: 2rem;
|
| 53 |
-
text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
|
| 54 |
}
|
| 55 |
.stTextArea label {
|
| 56 |
-
font-size: 1.
|
| 57 |
-
font-weight:
|
| 58 |
-
color: #
|
| 59 |
}
|
| 60 |
.stTextArea textarea {
|
| 61 |
-
|
| 62 |
-
border: none;
|
| 63 |
border-radius: 10px;
|
| 64 |
-
color: #ffffff;
|
| 65 |
font-size: 1rem;
|
| 66 |
-
padding:
|
| 67 |
}
|
| 68 |
.stButton button {
|
| 69 |
-
background: linear-gradient(45deg, #
|
| 70 |
color: white;
|
| 71 |
border: none;
|
| 72 |
border-radius: 30px;
|
|
@@ -80,33 +91,66 @@ st.markdown("""
|
|
| 80 |
transform: translateY(-2px);
|
| 81 |
box-shadow: 0 6px 8px rgba(0,0,0,0.15);
|
| 82 |
}
|
| 83 |
-
.
|
| 84 |
-
background
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
font-size: 0.9rem;
|
| 87 |
border-radius: 10px;
|
| 88 |
padding: 1rem;
|
| 89 |
margin-top: 1rem;
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
}
|
| 92 |
.stAlert {
|
| 93 |
-
background-color:
|
| 94 |
-
color: #
|
| 95 |
border-radius: 10px;
|
| 96 |
border: none;
|
|
|
|
| 97 |
}
|
| 98 |
.stSpinner {
|
| 99 |
-
color: #
|
| 100 |
}
|
| 101 |
</style>
|
| 102 |
""", unsafe_allow_html=True)
|
| 103 |
|
| 104 |
-
st.
|
| 105 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
-
|
|
|
|
| 108 |
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
| 110 |
if prompt.strip() == "":
|
| 111 |
st.error("Please enter a valid prompt.")
|
| 112 |
else:
|
|
@@ -114,13 +158,22 @@ if st.button("Generate Code"):
|
|
| 114 |
completed_text = generate_response(prompt)
|
| 115 |
st.success("Code generated successfully!")
|
| 116 |
|
| 117 |
-
|
| 118 |
code_blocks = completed_text.split("\n\n")
|
| 119 |
-
for block in code_blocks:
|
| 120 |
-
st.code
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
st.markdown("""
|
| 123 |
-
<div style='text-align: center; margin-top: 2rem; color:
|
| 124 |
-
Created with ❤️ by Your
|
| 125 |
</div>
|
| 126 |
-
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
| 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"])
|
|
|
|
| 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="Advanced AI Code Assistant", page_icon="🚀", layout="wide")
|
| 34 |
|
| 35 |
st.markdown("""
|
| 36 |
<style>
|
| 37 |
+
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&display=swap');
|
| 38 |
|
| 39 |
body {
|
| 40 |
+
font-family: 'Poppins', sans-serif;
|
| 41 |
+
background: linear-gradient(120deg, #84fab0 0%, #8fd3f4 100%);
|
| 42 |
+
color: #2c3e50;
|
| 43 |
}
|
| 44 |
.stApp {
|
| 45 |
+
max-width: 1200px;
|
| 46 |
margin: 0 auto;
|
| 47 |
padding: 2rem;
|
| 48 |
+
}
|
| 49 |
+
.main-container {
|
| 50 |
+
background: rgba(255, 255, 255, 0.95);
|
| 51 |
border-radius: 20px;
|
| 52 |
+
padding: 2rem;
|
| 53 |
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
|
| 54 |
}
|
| 55 |
h1 {
|
| 56 |
+
font-size: 2.5rem;
|
| 57 |
font-weight: 700;
|
| 58 |
+
color: #3498db;
|
| 59 |
+
text-align: center;
|
| 60 |
+
margin-bottom: 1rem;
|
| 61 |
+
}
|
| 62 |
+
.subtitle {
|
| 63 |
+
font-size: 1.2rem;
|
| 64 |
text-align: center;
|
| 65 |
+
color: #7f8c8d;
|
| 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 #3498db;
|
|
|
|
| 75 |
border-radius: 10px;
|
|
|
|
| 76 |
font-size: 1rem;
|
| 77 |
+
padding: 0.5rem;
|
| 78 |
}
|
| 79 |
.stButton button {
|
| 80 |
+
background: linear-gradient(45deg, #3498db, #2980b9);
|
| 81 |
color: white;
|
| 82 |
border: none;
|
| 83 |
border-radius: 30px;
|
|
|
|
| 91 |
transform: translateY(-2px);
|
| 92 |
box-shadow: 0 6px 8px rgba(0,0,0,0.15);
|
| 93 |
}
|
| 94 |
+
.output-container {
|
| 95 |
+
background: #f8f9fa;
|
| 96 |
+
border-radius: 10px;
|
| 97 |
+
padding: 1rem;
|
| 98 |
+
margin-top: 2rem;
|
| 99 |
+
}
|
| 100 |
+
.code-block {
|
| 101 |
+
background-color: #282c34;
|
| 102 |
+
color: #abb2bf;
|
| 103 |
+
font-family: 'Fira Code', monospace;
|
| 104 |
font-size: 0.9rem;
|
| 105 |
border-radius: 10px;
|
| 106 |
padding: 1rem;
|
| 107 |
margin-top: 1rem;
|
| 108 |
+
position: relative;
|
| 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: #e8f4fd;
|
| 128 |
+
color: #3498db;
|
| 129 |
border-radius: 10px;
|
| 130 |
border: none;
|
| 131 |
+
padding: 0.5rem 1rem;
|
| 132 |
}
|
| 133 |
.stSpinner {
|
| 134 |
+
color: #3498db;
|
| 135 |
}
|
| 136 |
</style>
|
| 137 |
""", unsafe_allow_html=True)
|
| 138 |
|
| 139 |
+
st.markdown('<div class="main-container">', unsafe_allow_html=True)
|
| 140 |
+
st.title("🚀 Advanced AI Code Assistant")
|
| 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=100)
|
| 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 generate_button:
|
| 154 |
if prompt.strip() == "":
|
| 155 |
st.error("Please enter a valid prompt.")
|
| 156 |
else:
|
|
|
|
| 158 |
completed_text = generate_response(prompt)
|
| 159 |
st.success("Code generated successfully!")
|
| 160 |
|
| 161 |
+
st.markdown('<div class="output-container">', unsafe_allow_html=True)
|
| 162 |
code_blocks = completed_text.split("\n\n")
|
| 163 |
+
for i, block in enumerate(code_blocks):
|
| 164 |
+
st.markdown(f'<div class="code-block">', unsafe_allow_html=True)
|
| 165 |
+
st.code(block, language=language.lower())
|
| 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: #7f8c8d;'>
|
| 175 |
+
Created with ❤️ by Your Advanced AI Code Assistant
|
| 176 |
</div>
|
| 177 |
+
""", unsafe_allow_html=True)
|
| 178 |
+
|
| 179 |
+
st.markdown('</div>', unsafe_allow_html=True)
|