Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- app.py +86 -0
- man-kddi.png +0 -0
- requirements.txt +1 -0
- robot.png +0 -0
app.py
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
import google.generativeai as genai
|
4 |
+
import time
|
5 |
+
|
6 |
+
os.environ["GOOGLE_API_KEY"] = os.getenv("GOOGLE_API_KEY")
|
7 |
+
genai.configure(api_key=os.environ["GOOGLE_API_KEY"])
|
8 |
+
|
9 |
+
icons = {"assistant": "robot.png", "user": "man-kddi.png"}
|
10 |
+
|
11 |
+
model = genai.GenerativeModel('gemini-1.5-flash-latest')
|
12 |
+
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.
|
13 |
+
Important note, If Question non-related to coding or programming means, you have to say: 'Please ask only coding-related questions.' except those kind of questions "who are you", "who created you".
|
14 |
+
previous_chat:
|
15 |
+
{chat_history}
|
16 |
+
Human: {human_input}
|
17 |
+
Chatbot:"""
|
18 |
+
|
19 |
+
previous_response = ""
|
20 |
+
def get_response(query):
|
21 |
+
global previous_response
|
22 |
+
|
23 |
+
for i in st.session_state['history']:
|
24 |
+
if i is not None:
|
25 |
+
previous_response += f"Human: {i[0]}\n Chatbot: {i[1]}\n"
|
26 |
+
|
27 |
+
response = model.generate_content(prompt.format(human_input=query, chat_history=previous_response))
|
28 |
+
st.session_state['history'].append((query, response.text))
|
29 |
+
return response.text
|
30 |
+
|
31 |
+
|
32 |
+
def response_streaming(text):
|
33 |
+
for i in text:
|
34 |
+
yield i
|
35 |
+
time.sleep(0.001)
|
36 |
+
|
37 |
+
st.title("GenXAi")
|
38 |
+
st.caption("I am Generative EXpert Assistant for Programming Related Task!")
|
39 |
+
|
40 |
+
st.markdown("""
|
41 |
+
<style>
|
42 |
+
.justified-text {
|
43 |
+
text-align: justify;
|
44 |
+
}
|
45 |
+
</style>
|
46 |
+
""", unsafe_allow_html=True)
|
47 |
+
|
48 |
+
with st.sidebar:
|
49 |
+
st.header("ABOUT:")
|
50 |
+
|
51 |
+
st.caption("""
|
52 |
+
<div class="justified-text">
|
53 |
+
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.
|
54 |
+
</div>
|
55 |
+
""", unsafe_allow_html=True)
|
56 |
+
|
57 |
+
for _ in range(17):
|
58 |
+
st.write("")
|
59 |
+
st.subheader("Build By:")
|
60 |
+
st.write("[Pachaiappan❤️](https://mr-vicky-01.github.io/Portfolio)")
|
61 |
+
st.write("contact: [Email](mailto:[email protected])")
|
62 |
+
|
63 |
+
if 'messages' not in st.session_state:
|
64 |
+
st.session_state.messages = [{'role': 'assistant', 'content': "I'm Here to help your programming realted questions😉"}]
|
65 |
+
|
66 |
+
if 'history' not in st.session_state:
|
67 |
+
st.session_state.history = []
|
68 |
+
|
69 |
+
for message in st.session_state.messages:
|
70 |
+
with st.chat_message(message['role'], avatar=icons[message['role']]):
|
71 |
+
st.write(message['content'])
|
72 |
+
|
73 |
+
user_input = st.chat_input("Ask Your Questions 👉..")
|
74 |
+
if user_input:
|
75 |
+
st.session_state.messages.append({'role': 'user', 'content': user_input})
|
76 |
+
with st.chat_message("user", avatar="man-kddi.png"):
|
77 |
+
st.write(user_input)
|
78 |
+
|
79 |
+
with st.spinner("Thinking..."):
|
80 |
+
response = get_response(user_input)
|
81 |
+
|
82 |
+
with st.chat_message("user", avatar="robot.png"):
|
83 |
+
st.write_stream(response_streaming(response))
|
84 |
+
|
85 |
+
message = {"role": "assistant", "content": response}
|
86 |
+
st.session_state.messages.append(message)
|
man-kddi.png
ADDED
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
google.generativeai
|
robot.png
ADDED