Spaces:
Runtime error
Runtime error
update app.py
Browse filesFixed chatbox issue and added module for user unput
app.py
CHANGED
@@ -1,12 +1,11 @@
|
|
1 |
import streamlit as st
|
2 |
import textwrap
|
3 |
import google.generativeai as genai
|
4 |
-
from IPython.display import display
|
5 |
from IPython.display import Markdown
|
6 |
import PIL.Image
|
|
|
|
|
7 |
|
8 |
-
def load_img(file_pth):
|
9 |
-
return PIL.Image.open(file_pth)
|
10 |
|
11 |
def to_markdown(text):
|
12 |
text = text.replace('•', ' *')
|
@@ -31,31 +30,36 @@ def chat(inpt_frm_vsn):
|
|
31 |
|
32 |
while True:
|
33 |
response = chat.send_message(res, generation_config=genai.types.GenerationConfig(
|
34 |
-
max_output_tokens=
|
35 |
))
|
36 |
to_markdown(response.text)
|
37 |
|
38 |
st.text('Gemini: ' + response.text)
|
39 |
-
res = st.
|
|
|
|
|
40 |
|
41 |
def main():
|
42 |
st.title("Gemini")
|
43 |
|
44 |
-
img_path = 'assets/apple.jpg'
|
45 |
-
img = load_img(img_path)
|
46 |
-
st.image(img, caption='Uploaded Image.', use_column_width=True)
|
47 |
|
48 |
GOOGLE_API_KEY = 'AIzaSyDMDS5TghIYsEV4nD6FsC8PDCtqGvkuUls'
|
49 |
|
50 |
genai.configure(api_key=GOOGLE_API_KEY)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
|
53 |
-
st.text(vision_result)
|
54 |
|
55 |
-
|
|
|
56 |
|
57 |
-
if check_point.lower() == 'nutrition':
|
58 |
-
chat(vision_result)
|
59 |
|
60 |
if __name__ == "__main__":
|
61 |
main()
|
|
|
1 |
import streamlit as st
|
2 |
import textwrap
|
3 |
import google.generativeai as genai
|
|
|
4 |
from IPython.display import Markdown
|
5 |
import PIL.Image
|
6 |
+
#from PIL import Image
|
7 |
+
|
8 |
|
|
|
|
|
9 |
|
10 |
def to_markdown(text):
|
11 |
text = text.replace('•', ' *')
|
|
|
30 |
|
31 |
while True:
|
32 |
response = chat.send_message(res, generation_config=genai.types.GenerationConfig(
|
33 |
+
max_output_tokens=100
|
34 |
))
|
35 |
to_markdown(response.text)
|
36 |
|
37 |
st.text('Gemini: ' + response.text)
|
38 |
+
res = st.chat_input('Please write your message here...')
|
39 |
+
if res:
|
40 |
+
st.write(f"User: {res}")
|
41 |
|
42 |
def main():
|
43 |
st.title("Gemini")
|
44 |
|
|
|
|
|
|
|
45 |
|
46 |
GOOGLE_API_KEY = 'AIzaSyDMDS5TghIYsEV4nD6FsC8PDCtqGvkuUls'
|
47 |
|
48 |
genai.configure(api_key=GOOGLE_API_KEY)
|
49 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
50 |
+
|
51 |
+
if uploaded_file is not None:
|
52 |
+
img = PIL.Image.open(uploaded_file)
|
53 |
+
st.image(img, caption='Uploaded Image', use_column_width=True)
|
54 |
+
|
55 |
+
vision_result = vision(img)
|
56 |
+
st.text(vision_result)
|
57 |
|
58 |
+
check_point = st.text_input("If you want to continue chat write 'Nutrition': ")
|
|
|
59 |
|
60 |
+
if check_point.lower() == 'nutrition':
|
61 |
+
chat(vision_result)
|
62 |
|
|
|
|
|
63 |
|
64 |
if __name__ == "__main__":
|
65 |
main()
|