Spaces:
Sleeping
Sleeping
Kushwanth Chowday Kandala commited on
Commit ·
8a0bbe5
1
Parent(s): 8eaa269
update with file upload feature app.py
Browse files
app.py
CHANGED
|
@@ -2,15 +2,12 @@ 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}")
|
|
@@ -20,15 +17,6 @@ model = genai.GenerativeModel('gemini-pro')
|
|
| 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"]},
|
|
@@ -51,4 +39,13 @@ 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"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import google.generativeai as genai
|
| 3 |
import os
|
| 4 |
|
|
|
|
| 5 |
gemini_api_key = os.getenv("GEMINI_API_KEY")
|
| 6 |
|
| 7 |
genai.configure(api_key = gemini_api_key)
|
| 8 |
|
| 9 |
model = genai.GenerativeModel('gemini-pro')
|
| 10 |
|
|
|
|
|
|
|
| 11 |
# prompt = st.chat_input("Say something")
|
| 12 |
# if prompt:
|
| 13 |
# st.write(f"User has sent the following prompt: {prompt}")
|
|
|
|
| 17 |
# message = st.chat_message("ai")
|
| 18 |
# message.write(response.text)
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
def chat_actions():
|
| 21 |
st.session_state["chat_history"].append(
|
| 22 |
{"role": "user", "content": st.session_state["chat_input"]},
|
|
|
|
| 39 |
|
| 40 |
for i in st.session_state["chat_history"]:
|
| 41 |
with st.chat_message(name=i["role"]):
|
| 42 |
+
st.write(i["content"])
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
import numpy as np
|
| 46 |
+
from PIL import Image
|
| 47 |
+
|
| 48 |
+
img_file_buffer = st.file_uploader('Upload a PNG image', type='png')
|
| 49 |
+
if img_file_buffer is not None:
|
| 50 |
+
image = Image.open(img_file_buffer)
|
| 51 |
+
img_array = np.array(image)
|