Spaces:
Sleeping
Sleeping
Kushwanth Chowday Kandala
commited on
Commit
·
fb84b3c
1
Parent(s):
1d9668c
update chat app.py
Browse files
app.py
CHANGED
|
@@ -1,55 +1,54 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
| 3 |
-
# from IPython.display import Markdown
|
| 4 |
import os
|
| 5 |
|
| 6 |
|
| 7 |
gemini_api_key = os.getenv("GEMINI_API_KEY")
|
| 8 |
|
| 9 |
-
|
| 10 |
-
# def to_markdown(text):
|
| 11 |
-
# text = text.replace('•', ' *')
|
| 12 |
-
# return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True)
|
| 13 |
-
|
| 14 |
-
import google.generativeai as genai
|
| 15 |
-
|
| 16 |
genai.configure(api_key = gemini_api_key)
|
| 17 |
|
| 18 |
model = genai.GenerativeModel('gemini-pro')
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
-
prompt = st.chat_input("Say something")
|
| 23 |
-
if prompt:
|
| 24 |
-
|
| 25 |
-
else:
|
| 26 |
-
|
| 27 |
-
response = model.generate_content(prompt)
|
| 28 |
-
message = st.chat_message("ai")
|
| 29 |
-
message.write(response.text)
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
# # Get the user's name from the text input
|
| 34 |
-
# name = st.text_input("Enter your name:")
|
| 35 |
|
| 36 |
-
# # Greet the user
|
| 37 |
-
# st.write(f"Hello, {name}!")
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
# x = st.slider('Select a value')
|
| 47 |
-
# st.write(x, 'squared is', x * x)
|
| 48 |
|
|
|
|
|
|
|
| 49 |
|
| 50 |
-
# st.title('AI Fitness Trainer: Squats Analysis')
|
| 51 |
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import google.generativeai as genai
|
|
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
|
| 6 |
gemini_api_key = os.getenv("GEMINI_API_KEY")
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
genai.configure(api_key = gemini_api_key)
|
| 9 |
|
| 10 |
model = genai.GenerativeModel('gemini-pro')
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
+
# prompt = st.chat_input("Say something")
|
| 15 |
+
# if prompt:
|
| 16 |
+
# st.write(f"User has sent the following prompt: {prompt}")
|
| 17 |
+
# else:
|
| 18 |
+
# prompt = "who are you?"
|
| 19 |
+
# response = model.generate_content(prompt)
|
| 20 |
+
# message = st.chat_message("ai")
|
| 21 |
+
# message.write(response.text)
|
| 22 |
+
|
| 23 |
|
| 24 |
+
import string
|
| 25 |
+
import random
|
|
|
|
|
|
|
| 26 |
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
def randon_string() -> str:
|
| 29 |
+
return "".join(random.choices(string.ascii_uppercase + string.digits, k=10))
|
| 30 |
|
| 31 |
|
| 32 |
+
def chat_actions():
|
| 33 |
+
st.session_state["chat_history"].append(
|
| 34 |
+
{"role": "user", "content": st.session_state["chat_input"]},
|
| 35 |
+
)
|
| 36 |
|
| 37 |
+
response = model.generate_content(st.session_state["chat_input"])
|
| 38 |
+
st.session_state["chat_history"].append(
|
| 39 |
+
{
|
| 40 |
+
"role": "assistant",
|
| 41 |
+
"content": response,
|
| 42 |
+
}, # This can be replaced with your chat response logic
|
| 43 |
+
)
|
| 44 |
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
if "chat_history" not in st.session_state:
|
| 47 |
+
st.session_state["chat_history"] = []
|
| 48 |
|
|
|
|
| 49 |
|
| 50 |
+
st.chat_input("Enter your message", on_submit=chat_actions, key="chat_input")
|
| 51 |
|
| 52 |
+
for i in st.session_state["chat_history"]:
|
| 53 |
+
with st.chat_message(name=i["role"]):
|
| 54 |
+
st.write(i["content"])
|