louiecerv commited on
Commit
97bf51a
·
1 Parent(s): 8ed09a1

sync wtih remote

Browse files
Files changed (2) hide show
  1. app.py +69 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tempfile
3
+ from PIL import Image
4
+ import google.generativeai as genai
5
+ import os
6
+
7
+ MODEL_ID = "gemini-2.0-flash-exp"
8
+ api_key = os.getenv("GEMINI_API_KEY")
9
+ model_id = MODEL_ID
10
+ genai.configure(api_key=api_key)
11
+
12
+ if "model" not in st.session_state:
13
+ st.session_state.model = genai.GenerativeModel(MODEL_ID)
14
+
15
+ model = st.session_state.model
16
+ chat = model.start_chat()
17
+ mime_type = "image/jpeg" # Use a consistent MIME type for images
18
+
19
+
20
+
21
+ # Dummy AI model function
22
+ def ai_model(image_path):
23
+ """
24
+ This is a dummy AI model function that will be replaced with
25
+ the actual multimodal AI model.
26
+ """
27
+ return "The AI model response based on the image."
28
+
29
+ def main():
30
+ st.title("Image Processing with AI")
31
+ img_file_buffer = None
32
+ image_path = ""
33
+
34
+ # Use the camera to capture an image
35
+ img_file_buffer = st.camera_input("Take a picture")
36
+
37
+ if img_file_buffer is not None:
38
+ # Save the image to a temporary file
39
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file:
40
+ temp_file.write(img_file_buffer.read())
41
+ image_path = temp_file.name
42
+ st.write("Image saved to:", image_path)
43
+ #st.image(Image.open(image_path), caption="Captured Image", use_container_width=True)
44
+
45
+ user_input = st.text_area("Enter your prompt:", height=200)
46
+ prompt =f"Refer to the image. Perform the task or answer the question {user_input}"
47
+
48
+ if st.button("Process the image"):
49
+ if prompt:
50
+ with st.spinner("Processing..."):
51
+ # Upload the file with the correct MIME type
52
+ file_data = genai.upload_file(image_path, mime_type=mime_type)
53
+
54
+ # Send file and prompt to Gemini API
55
+ response = chat.send_message(
56
+ [
57
+ prompt,
58
+ file_data
59
+ ]
60
+ )
61
+
62
+ # Display Gemini response
63
+ st.markdown(response.text)
64
+ else:
65
+ st.warning("Please provide a valid prompt.")
66
+
67
+
68
+ if __name__ == "__main__":
69
+ main()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit
2
+ google-generativeai