Upload app.py
Browse files
app.py
CHANGED
|
@@ -13,12 +13,12 @@ os.environ["AIzaSyBLb8HjkkkcTJXZWwfHQJTQJQHXsylHRVA"] = api_key
|
|
| 13 |
icons = {"assistant": "robot.png", "user": "man-kddi.png"}
|
| 14 |
|
| 15 |
model = genai.GenerativeModel('gemini-1.5-flash-latest')
|
| 16 |
-
prompt = """
|
| 17 |
-
|
| 18 |
-
|
| 19 |
{chat_history}
|
| 20 |
-
|
| 21 |
-
|
| 22 |
|
| 23 |
previous_response = ""
|
| 24 |
def get_response(query):
|
|
@@ -26,7 +26,7 @@ def get_response(query):
|
|
| 26 |
|
| 27 |
for i in st.session_state['history']:
|
| 28 |
if i is not None:
|
| 29 |
-
previous_response += f"
|
| 30 |
|
| 31 |
response = model.generate_content(prompt.format(human_input=query, chat_history=previous_response))
|
| 32 |
st.session_state['history'].append((query, response.text))
|
|
@@ -38,8 +38,8 @@ def response_streaming(text):
|
|
| 38 |
yield i
|
| 39 |
time.sleep(0.001)
|
| 40 |
|
| 41 |
-
st.title("
|
| 42 |
-
st.caption("
|
| 43 |
|
| 44 |
st.markdown("""
|
| 45 |
<style>
|
|
@@ -50,22 +50,22 @@ st.markdown("""
|
|
| 50 |
""", unsafe_allow_html=True)
|
| 51 |
|
| 52 |
with st.sidebar:
|
| 53 |
-
st.header("
|
| 54 |
|
| 55 |
st.caption("""
|
| 56 |
<div class="justified-text">
|
| 57 |
-
|
| 58 |
</div>
|
| 59 |
""", unsafe_allow_html=True)
|
| 60 |
|
| 61 |
for _ in range(17):
|
| 62 |
st.write("")
|
| 63 |
-
st.subheader("
|
| 64 |
-
st.write("[
|
| 65 |
-
st.write("
|
| 66 |
|
| 67 |
if 'messages' not in st.session_state:
|
| 68 |
-
st.session_state.messages = [{'role': 'assistant', 'content': "
|
| 69 |
|
| 70 |
if 'history' not in st.session_state:
|
| 71 |
st.session_state.history = []
|
|
@@ -74,17 +74,17 @@ for message in st.session_state.messages:
|
|
| 74 |
with st.chat_message(message['role'], avatar=icons[message['role']]):
|
| 75 |
st.write(message['content'])
|
| 76 |
|
| 77 |
-
user_input = st.chat_input("
|
| 78 |
if user_input:
|
| 79 |
st.session_state.messages.append({'role': 'user', 'content': user_input})
|
| 80 |
with st.chat_message("user", avatar="man-kddi.png"):
|
| 81 |
st.write(user_input)
|
| 82 |
|
| 83 |
-
with st.spinner("
|
| 84 |
response = get_response(user_input)
|
| 85 |
|
| 86 |
with st.chat_message("user", avatar="robot.png"):
|
| 87 |
st.write_stream(response_streaming(response))
|
| 88 |
|
| 89 |
message = {"role": "assistant", "content": response}
|
| 90 |
-
st.session_state.messages.append(message)
|
|
|
|
| 13 |
icons = {"assistant": "robot.png", "user": "man-kddi.png"}
|
| 14 |
|
| 15 |
model = genai.GenerativeModel('gemini-1.5-flash-latest')
|
| 16 |
+
prompt = """You are a programming teaching assistant named GenXAI(Generative eXpert AI), created by Pachaiappan [linkdin](https://www.linkedin.com/in/pachaiappan) an AI Specialist. Answer only the programming, error-fixing and code-related question that being asked.
|
| 17 |
+
Important note, If Question non-related to coding or programming means, you have to say: 'Please ask only coding-related questions.' except greeting and those kind of questions "who are you", "who created you".
|
| 18 |
+
previous_chat:
|
| 19 |
{chat_history}
|
| 20 |
+
Human: {human_input}
|
| 21 |
+
Chatbot:"""
|
| 22 |
|
| 23 |
previous_response = ""
|
| 24 |
def get_response(query):
|
|
|
|
| 26 |
|
| 27 |
for i in st.session_state['history']:
|
| 28 |
if i is not None:
|
| 29 |
+
previous_response += f"Human: {i[0]}\n Chatbot: {i[1]}\n"
|
| 30 |
|
| 31 |
response = model.generate_content(prompt.format(human_input=query, chat_history=previous_response))
|
| 32 |
st.session_state['history'].append((query, response.text))
|
|
|
|
| 38 |
yield i
|
| 39 |
time.sleep(0.001)
|
| 40 |
|
| 41 |
+
st.title("GenXAi")
|
| 42 |
+
st.caption("I am Generative EXpert Assistant for Programming Related Task!")
|
| 43 |
|
| 44 |
st.markdown("""
|
| 45 |
<style>
|
|
|
|
| 50 |
""", unsafe_allow_html=True)
|
| 51 |
|
| 52 |
with st.sidebar:
|
| 53 |
+
st.header("ABOUT:")
|
| 54 |
|
| 55 |
st.caption("""
|
| 56 |
<div class="justified-text">
|
| 57 |
+
This is GenXai (Generation Expert AI), designed to assist with programming-related questions. This AI can help you answer your coding queries, fix errors, and much more. Additionally, you can chat with GenXai to build and refine your questions, facilitating a more productive conversation.
|
| 58 |
</div>
|
| 59 |
""", unsafe_allow_html=True)
|
| 60 |
|
| 61 |
for _ in range(17):
|
| 62 |
st.write("")
|
| 63 |
+
st.subheader("Build By:")
|
| 64 |
+
st.write("[madji❤️](https://www.facebook.com/madjioff)")
|
| 65 |
+
st.write("contact: [Email](mailto:madjioff@gamil.com)")
|
| 66 |
|
| 67 |
if 'messages' not in st.session_state:
|
| 68 |
+
st.session_state.messages = [{'role': 'assistant', 'content': "I'm Here to help your programming realted questions😉"}]
|
| 69 |
|
| 70 |
if 'history' not in st.session_state:
|
| 71 |
st.session_state.history = []
|
|
|
|
| 74 |
with st.chat_message(message['role'], avatar=icons[message['role']]):
|
| 75 |
st.write(message['content'])
|
| 76 |
|
| 77 |
+
user_input = st.chat_input("Ask Your Questions 👉..")
|
| 78 |
if user_input:
|
| 79 |
st.session_state.messages.append({'role': 'user', 'content': user_input})
|
| 80 |
with st.chat_message("user", avatar="man-kddi.png"):
|
| 81 |
st.write(user_input)
|
| 82 |
|
| 83 |
+
with st.spinner("Thinking..."):
|
| 84 |
response = get_response(user_input)
|
| 85 |
|
| 86 |
with st.chat_message("user", avatar="robot.png"):
|
| 87 |
st.write_stream(response_streaming(response))
|
| 88 |
|
| 89 |
message = {"role": "assistant", "content": response}
|
| 90 |
+
st.session_state.messages.append(message)
|