Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,24 +7,39 @@ os.environ["GOOGLE_API_KEY"] = os.getenv("GOOGLE_API_KEY")
|
|
| 7 |
genai.configure(api_key=os.environ["GOOGLE_API_KEY"])
|
| 8 |
|
| 9 |
model = genai.GenerativeModel('gemini-1.5-flash-latest')
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
|
|
|
|
| 14 |
def get_response(query):
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
return response.text
|
| 17 |
|
|
|
|
| 18 |
def response_streaming(text):
|
| 19 |
for i in text:
|
| 20 |
yield i
|
| 21 |
time.sleep(0.001)
|
| 22 |
|
| 23 |
st.title("GenXAi")
|
| 24 |
-
st.text("I am Generative EXpert Assistant")
|
| 25 |
|
| 26 |
if 'messages' not in st.session_state:
|
| 27 |
st.session_state.messages = [{'role': 'assistant', 'content': "I'm Here to help your programming realted questions"}]
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
for message in st.session_state.messages:
|
| 30 |
with st.chat_message(message['role']):
|
|
|
|
| 7 |
genai.configure(api_key=os.environ["GOOGLE_API_KEY"])
|
| 8 |
|
| 9 |
model = genai.GenerativeModel('gemini-1.5-flash-latest')
|
| 10 |
+
prompt = """You are a programming teaching assistant named GenXAI(Generative eXpert AI), created by Pachaiappan. Answer only the programming, error-fixing and code-related question that being asked.
|
| 11 |
+
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".
|
| 12 |
+
previous_chat:
|
| 13 |
+
{chat_history}
|
| 14 |
+
Human: {human_input}
|
| 15 |
+
Chatbot:"""
|
| 16 |
|
| 17 |
+
previous_response = ""
|
| 18 |
def get_response(query):
|
| 19 |
+
global previous_response
|
| 20 |
+
|
| 21 |
+
for i in st.session_state['history']:
|
| 22 |
+
if i is not None:
|
| 23 |
+
previous_response += f"Human: {i[0]}\n Chatbot: {i[1]}\n"
|
| 24 |
+
|
| 25 |
+
response = model.generate_content(prompt.format(human_input=query, chat_history=previous_response))
|
| 26 |
+
st.session_state['history'].append((query, response.text))
|
| 27 |
return response.text
|
| 28 |
|
| 29 |
+
|
| 30 |
def response_streaming(text):
|
| 31 |
for i in text:
|
| 32 |
yield i
|
| 33 |
time.sleep(0.001)
|
| 34 |
|
| 35 |
st.title("GenXAi")
|
| 36 |
+
st.text("I am Generative EXpert Assistant for Programming Related Task!")
|
| 37 |
|
| 38 |
if 'messages' not in st.session_state:
|
| 39 |
st.session_state.messages = [{'role': 'assistant', 'content': "I'm Here to help your programming realted questions"}]
|
| 40 |
+
|
| 41 |
+
if 'history' not in st.session_state:
|
| 42 |
+
st.session_state.history = []
|
| 43 |
|
| 44 |
for message in st.session_state.messages:
|
| 45 |
with st.chat_message(message['role']):
|