deep-div commited on
Commit
bcf7084
·
verified ·
1 Parent(s): 7877694

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -85
app.py CHANGED
@@ -1,86 +1,81 @@
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": "chat.png", "user": "person.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 greeting and 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:pachaiappan1102@gamil.com)")
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="chat.png"):
83
- st.write_stream(response_streaming(response))
84
-
85
- message = {"role": "assistant", "content": response}
86
  st.session_state.messages.append(message)
 
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": "chat.png", "user": "person.png"}
10
+
11
+ model = genai.GenerativeModel('gemini-1.5-flash-latest')
12
+ prompt = """You are a programming teaching assistant named CodeMate. Answer only the programming, error-fixing and code-related questions that are being asked.
13
+ Important note: If the question is non-related to coding or programming, you have to say: 'Please ask only coding-related questions.' except for greetings and questions like "Who are you?" or "Who created you?".
14
+ previous_chat:
15
+ {chat_history}
16
+ Human: {human_input}
17
+ Chatbot:"""
18
+
19
+
20
+ previous_response = ""
21
+ def get_response(query):
22
+ global previous_response
23
+
24
+ for i in st.session_state['history']:
25
+ if i is not None:
26
+ previous_response += f"Human: {i[0]}\n Chatbot: {i[1]}\n"
27
+
28
+ response = model.generate_content(prompt.format(human_input=query, chat_history=previous_response))
29
+ st.session_state['history'].append((query, response.text))
30
+ return response.text
31
+
32
+
33
+ def response_streaming(text):
34
+ for i in text:
35
+ yield i
36
+ time.sleep(0.001)
37
+
38
+ st.title("GenXAi")
39
+ st.caption("I am Generative EXpert Assistant for Programming Related Task!")
40
+
41
+ st.markdown("""
42
+ <style>
43
+ .justified-text {
44
+ text-align: justify;
45
+ }
46
+ </style>
47
+ """, unsafe_allow_html=True)
48
+
49
+ with st.sidebar:
50
+ st.header("ABOUT:")
51
+
52
+ st.caption("""
53
+ <div class="justified-text">
54
+ This is CodeMate, 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 CodeMate to build and refine your questions, facilitating a more productive conversation.
55
+ </div>
56
+ """, unsafe_allow_html=True)
57
+
58
+ if 'messages' not in st.session_state:
59
+ st.session_state.messages = [{'role': 'assistant', 'content': "I'm Here to help your programming realted questions😉"}]
60
+
61
+ if 'history' not in st.session_state:
62
+ st.session_state.history = []
63
+
64
+ for message in st.session_state.messages:
65
+ with st.chat_message(message['role'], avatar=icons[message['role']]):
66
+ st.write(message['content'])
67
+
68
+ user_input = st.chat_input("Ask Your Questions 👉..")
69
+ if user_input:
70
+ st.session_state.messages.append({'role': 'user', 'content': user_input})
71
+ with st.chat_message("user", avatar="man-kddi.png"):
72
+ st.write(user_input)
73
+
74
+ with st.spinner("Thinking..."):
75
+ response = get_response(user_input)
76
+
77
+ with st.chat_message("user", avatar="chat.png"):
78
+ st.write_stream(response_streaming(response))
79
+
80
+ message = {"role": "assistant", "content": response}
 
 
 
 
 
81
  st.session_state.messages.append(message)