| import os |
| import streamlit as st |
| import google.generativeai as genai |
| import requests |
| import json |
|
|
| |
| 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 be concise, accurate, and helpful.", |
| ) |
| chat_session = model.start_chat(history=[]) |
|
|
| def generate_response(user_input): |
| response = chat_session.send_message(user_input) |
| return response.text |
|
|
| def load_lottieurl(url: str): |
| r = requests.get(url) |
| if r.status_code != 200: |
| return None |
| return r.json() |
|
|
| |
| lottie_url = "https://assets7.lottiefiles.com/packages/lf20_s1jf29.json" |
| lottie_json = load_lottieurl(lottie_url) |
|
|
| |
| st.set_page_config(page_title="AI Code Assistant", page_icon="🤖", layout="wide") |
|
|
| st.title("🤖 AI Code Assistant") |
| st.markdown("#### Powered by Google Gemini") |
|
|
| if lottie_json: |
| st_lottie(lottie_json, height=300, key="coding") |
|
|
| prompt = st.text_area("Enter your coding question or request:", height=150) |
|
|
| if st.button("Generate Response"): |
| if prompt.strip() == "": |
| st.error("Please enter a valid prompt.") |
| else: |
| with st.spinner("Generating response..."): |
| completed_text = generate_response(prompt) |
| st.success("Response generated successfully!") |
| st.text_area("Ath's Response:", completed_text, height=200) |
|
|
| st.markdown(""" |
| <style> |
| .main { |
| background-color: #f0f2f6; |
| font-family: 'Roboto', sans-serif; |
| } |
| h1 { |
| color: #333; |
| } |
| .stTextArea label { |
| font-size: 1.2rem; |
| color: #333; |
| } |
| .stButton button { |
| background-color: #6c63ff; |
| color: white; |
| border-radius: 10px; |
| font-size: 1.1rem; |
| } |
| .stButton button:hover { |
| background-color: #5a52d1; |
| } |
| .sidebar .sidebar-content { |
| background-color: #4b4c5c; |
| } |
| .sidebar .sidebar-content select { |
| color: white; |
| background-color: #4b4c5c; |
| } |
| .sidebar .sidebar-content label { |
| color: white; |
| } |
| </style> |
| """, unsafe_allow_html=True) |