Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import os
|
|
2 |
import streamlit as st
|
3 |
import google.generativeai as genai
|
4 |
import requests
|
5 |
-
import json
|
6 |
|
7 |
# Configure the Gemini API
|
8 |
genai.configure(api_key=st.secrets["GOOGLE_API_KEY"])
|
@@ -19,7 +18,7 @@ generation_config = {
|
|
19 |
model = genai.GenerativeModel(
|
20 |
model_name="gemini-1.5-pro",
|
21 |
generation_config=generation_config,
|
22 |
-
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
|
23 |
)
|
24 |
chat_session = model.start_chat(history=[])
|
25 |
|
@@ -56,10 +55,21 @@ if st.button("Generate Code"):
|
|
56 |
completed_text = generate_response(prompt)
|
57 |
st.success("Code generated successfully!")
|
58 |
|
59 |
-
#
|
60 |
-
|
61 |
-
|
62 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
st.markdown("""
|
65 |
<style>
|
|
|
2 |
import streamlit as st
|
3 |
import google.generativeai as genai
|
4 |
import requests
|
|
|
5 |
|
6 |
# Configure the Gemini API
|
7 |
genai.configure(api_key=st.secrets["GOOGLE_API_KEY"])
|
|
|
18 |
model = genai.GenerativeModel(
|
19 |
model_name="gemini-1.5-pro",
|
20 |
generation_config=generation_config,
|
21 |
+
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 include HTML, CSS, and JavaScript code separately when applicable, with clear section headers for each type of code.",
|
22 |
)
|
23 |
chat_session = model.start_chat(history=[])
|
24 |
|
|
|
55 |
completed_text = generate_response(prompt)
|
56 |
st.success("Code generated successfully!")
|
57 |
|
58 |
+
# Display code blocks based on predefined markers
|
59 |
+
if "HTML:" in completed_text:
|
60 |
+
html_code = completed_text.split("HTML:")[1].split("CSS:")[0].strip()
|
61 |
+
st.subheader("HTML Code")
|
62 |
+
st.code(html_code, language="html")
|
63 |
+
|
64 |
+
if "CSS:" in completed_text:
|
65 |
+
css_code = completed_text.split("CSS:")[1].split("JavaScript:")[0].strip()
|
66 |
+
st.subheader("CSS Code")
|
67 |
+
st.code(css_code, language="css")
|
68 |
+
|
69 |
+
if "JavaScript:" in completed_text:
|
70 |
+
js_code = completed_text.split("JavaScript:")[1].strip()
|
71 |
+
st.subheader("JavaScript Code")
|
72 |
+
st.code(js_code, language="javascript")
|
73 |
|
74 |
st.markdown("""
|
75 |
<style>
|