ositamiles commited on
Commit
9ebd40b
·
verified ·
1 Parent(s): 7e69dc6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ import openai
4
+ import cv2
5
+ import numpy as np
6
+ import tensorflow as tf
7
+
8
+ # Set OpenAI API key
9
+ openai.api_key = "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"
10
+
11
+ # Title of the app
12
+ st.title("AttraVision - Compare and Analyze Attractiveness")
13
+
14
+ # Uploading the images
15
+ st.header("Upload Two Photos for Comparison")
16
+ uploaded_file1 = st.file_uploader("Choose the first image", type=["jpg", "jpeg", "png"])
17
+ uploaded_file2 = st.file_uploader("Choose the second image", type=["jpg", "jpeg", "png"])
18
+
19
+ # Helper function to process image
20
+ def process_image(image_file):
21
+ img = Image.open(image_file)
22
+ img = img.resize((224, 224)) # Resize image for consistent input size
23
+ img_array = np.array(img)
24
+ return img_array
25
+
26
+ # Helper function to analyze image using OpenAI
27
+ def analyze_image(image_array):
28
+ # Convert the image to bytes to send to OpenAI API
29
+ img_bytes = Image.fromarray(image_array).tobytes()
30
+
31
+ # Use OpenAI's image recognition model to analyze the photo (vision capabilities)
32
+ response = openai.Image.create(file=img_bytes)
33
+ # You can extract specific insights such as facial features or symmetry
34
+ return response["data"] # Example response handling
35
+
36
+ # Analyze and compare the two photos
37
+ if uploaded_file1 and uploaded_file2:
38
+ # Display the uploaded images
39
+ st.image([uploaded_file1, uploaded_file2], caption=["Photo 1", "Photo 2"], width=300)
40
+
41
+ # Process and analyze the images
42
+ img1 = process_image(uploaded_file1)
43
+ img2 = process_image(uploaded_file2)
44
+
45
+ st.write("Analyzing photos...")
46
+
47
+ # Analyze the first image
48
+ analysis1 = analyze_image(img1)
49
+ st.write("Photo 1 Analysis: ", analysis1)
50
+
51
+ # Analyze the second image
52
+ analysis2 = analyze_image(img2)
53
+ st.write("Photo 2 Analysis: ", analysis2)
54
+
55
+ # Example of comparison logic (this could be extended for metrics like symmetry)
56
+ if analysis1["symmetry_score"] > analysis2["symmetry_score"]:
57
+ st.write("Photo 1 is more symmetrical than Photo 2.")
58
+ else:
59
+ st.write("Photo 2 is more symmetrical than Photo 1.")
60
+
61
+ # Provide more detailed metrics such as emotion, lighting, etc.
62
+ st.write("Additional metrics such as emotion, lighting, etc., will be added here.")
63
+
64
+ else:
65
+ st.write("Please upload two images to compare.")