| | import streamlit as st |
| | import google.generativeai as genai |
| | import requests |
| |
|
| | |
| | genai.configure(api_key=st.secrets["GOOGLE_API_KEY"]) |
| |
|
| | |
| | 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 |
| |
|
| | |
| | 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!") |
| | |
| | |
| | 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) |