Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import google.generativeai as genai
|
| 3 |
-
from PIL import Image
|
| 4 |
import os
|
| 5 |
-
import time
|
| 6 |
|
| 7 |
# Configure the API key
|
| 8 |
api_key = 'AIzaSyC13hxiLDZQagfXybLKCklbTlBDsO4vHwQ'
|
|
@@ -13,21 +11,12 @@ def process_image(image_path, user_question=None):
|
|
| 13 |
try:
|
| 14 |
# Upload the image to Google Generative AI
|
| 15 |
sample_file = genai.upload_file(path=image_path, display_name="Sample drawing")
|
| 16 |
-
#st.write(f"Uploaded file '{sample_file.display_name}' as: {sample_file.uri}")
|
| 17 |
-
|
| 18 |
-
# Retrieve the uploaded file
|
| 19 |
-
file = genai.get_file(name=sample_file.name)
|
| 20 |
-
#st.write(f"Retrieved file '{file.display_name}' as: {sample_file.uri}")
|
| 21 |
|
| 22 |
# Use the Generative AI model to analyze the image
|
| 23 |
model = genai.GenerativeModel(model_name="models/gemini-2.0-flash-exp")
|
| 24 |
|
| 25 |
# Prepare the prompt
|
| 26 |
-
if user_question
|
| 27 |
-
prompt = user_question
|
| 28 |
-
else:
|
| 29 |
-
prompt = "Explain the scene in the image in detail."
|
| 30 |
-
|
| 31 |
response = model.generate_content([prompt, sample_file])
|
| 32 |
|
| 33 |
# Display the response
|
|
@@ -36,7 +25,6 @@ def process_image(image_path, user_question=None):
|
|
| 36 |
|
| 37 |
# Delete the uploaded file
|
| 38 |
genai.delete_file(sample_file.name)
|
| 39 |
-
#st.write(f"Deleted {sample_file.display_name}.")
|
| 40 |
|
| 41 |
except Exception as e:
|
| 42 |
st.error(f"An error occurred: {e}")
|
|
@@ -60,11 +48,18 @@ def set_cyberpunk_style():
|
|
| 60 |
}
|
| 61 |
|
| 62 |
.stButton button {
|
| 63 |
-
background-color: #
|
| 64 |
-
color: #
|
| 65 |
-
border: 2px solid #00ff00;
|
| 66 |
font-family: 'Orbitron', sans-serif;
|
| 67 |
font-weight: bold;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
}
|
| 69 |
|
| 70 |
.stTextInput input {
|
|
@@ -101,7 +96,7 @@ def main():
|
|
| 101 |
set_cyberpunk_style()
|
| 102 |
|
| 103 |
# App title and description
|
| 104 |
-
st.title("VisioX:
|
| 105 |
st.markdown(
|
| 106 |
"""
|
| 107 |
<div style="color: #00ff00;">
|
|
@@ -124,7 +119,7 @@ def main():
|
|
| 124 |
|
| 125 |
# Display the captured image
|
| 126 |
st.markdown("### Captured Image")
|
| 127 |
-
st.image(image_path, caption="Your Moment"
|
| 128 |
|
| 129 |
# Add a text input for user questions
|
| 130 |
st.markdown("### Ask a Question")
|
|
@@ -141,7 +136,6 @@ def main():
|
|
| 141 |
|
| 142 |
# Clean up the temporary file
|
| 143 |
os.remove(image_path)
|
| 144 |
-
#st.write("Temporary image file deleted.")
|
| 145 |
|
| 146 |
# Run the app
|
| 147 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import google.generativeai as genai
|
|
|
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
# Configure the API key
|
| 6 |
api_key = 'AIzaSyC13hxiLDZQagfXybLKCklbTlBDsO4vHwQ'
|
|
|
|
| 11 |
try:
|
| 12 |
# Upload the image to Google Generative AI
|
| 13 |
sample_file = genai.upload_file(path=image_path, display_name="Sample drawing")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# Use the Generative AI model to analyze the image
|
| 16 |
model = genai.GenerativeModel(model_name="models/gemini-2.0-flash-exp")
|
| 17 |
|
| 18 |
# Prepare the prompt
|
| 19 |
+
prompt = user_question if user_question else "Explain the scene in the image in detail."
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
response = model.generate_content([prompt, sample_file])
|
| 21 |
|
| 22 |
# Display the response
|
|
|
|
| 25 |
|
| 26 |
# Delete the uploaded file
|
| 27 |
genai.delete_file(sample_file.name)
|
|
|
|
| 28 |
|
| 29 |
except Exception as e:
|
| 30 |
st.error(f"An error occurred: {e}")
|
|
|
|
| 48 |
}
|
| 49 |
|
| 50 |
.stButton button {
|
| 51 |
+
background-color: #000000 !important;
|
| 52 |
+
color: #00ff00 !important;
|
| 53 |
+
border: 2px solid #00ff00 !important;
|
| 54 |
font-family: 'Orbitron', sans-serif;
|
| 55 |
font-weight: bold;
|
| 56 |
+
transition: all 0.3s ease;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
.stButton button:hover {
|
| 60 |
+
background-color: #00ff00 !important;
|
| 61 |
+
color: #000000 !important;
|
| 62 |
+
border: 2px solid #000000 !important;
|
| 63 |
}
|
| 64 |
|
| 65 |
.stTextInput input {
|
|
|
|
| 96 |
set_cyberpunk_style()
|
| 97 |
|
| 98 |
# App title and description
|
| 99 |
+
st.title("VisioX : SXR")
|
| 100 |
st.markdown(
|
| 101 |
"""
|
| 102 |
<div style="color: #00ff00;">
|
|
|
|
| 119 |
|
| 120 |
# Display the captured image
|
| 121 |
st.markdown("### Captured Image")
|
| 122 |
+
st.image(image_path, caption="Your Moment")
|
| 123 |
|
| 124 |
# Add a text input for user questions
|
| 125 |
st.markdown("### Ask a Question")
|
|
|
|
| 136 |
|
| 137 |
# Clean up the temporary file
|
| 138 |
os.remove(image_path)
|
|
|
|
| 139 |
|
| 140 |
# Run the app
|
| 141 |
if __name__ == "__main__":
|