Spaces:
Running
Running
Kushwanth Chowday Kandala
commited on
Commit
•
31c48ce
1
Parent(s):
ed9a03b
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import google.generativeai as genai
|
3 |
+
import os
|
4 |
+
from streamlit_chat import message
|
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 |
+
# prompt = st.chat_input("Say something")
|
13 |
+
# if prompt:
|
14 |
+
# st.write(f"User has sent the following prompt: {prompt}")
|
15 |
+
# else:
|
16 |
+
# prompt = "who are you?"
|
17 |
+
# response = model.generate_content(prompt)
|
18 |
+
# message = st.chat_message("ai")
|
19 |
+
# message.write(response.text)
|
20 |
+
|
21 |
+
def chat_actions():
|
22 |
+
st.session_state["chat_history"].append(
|
23 |
+
{"role": "user", "content": st.session_state["chat_input"]},
|
24 |
+
)
|
25 |
+
|
26 |
+
response = model.generate_content(st.session_state["chat_input"])
|
27 |
+
st.session_state["chat_history"].append(
|
28 |
+
{
|
29 |
+
"role": "assistant",
|
30 |
+
"content": response.text,
|
31 |
+
}, # This can be replaced with your chat response logic
|
32 |
+
)
|
33 |
+
|
34 |
+
|
35 |
+
if "chat_history" not in st.session_state:
|
36 |
+
st.session_state["chat_history"] = []
|
37 |
+
|
38 |
+
|
39 |
+
st.chat_input("Enter your message", on_submit=chat_actions, key="chat_input")
|
40 |
+
|
41 |
+
for i in st.session_state["chat_history"]:
|
42 |
+
with st.chat_message(name=i["role"]):
|
43 |
+
st.write(i["content"])
|
44 |
+
|
45 |
+
|
46 |
+
# import numpy as np
|
47 |
+
# from PIL import Image
|
48 |
+
|
49 |
+
# img_file_buffer = st.file_uploader('Upload a PNG image', on_change= type=['png','jpg'])
|
50 |
+
# if img_file_buffer is not None:
|
51 |
+
# image = Image.open(img_file_buffer)
|
52 |
+
# img_array = np.array(image)
|