clarice7 commited on
Commit
e1c9862
1 Parent(s): 424cf41

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -3,6 +3,7 @@ import os
3
  import csv
4
  import requests
5
  import time
 
6
  import pandas as pd
7
  import openai
8
  from openai import OpenAI
@@ -21,6 +22,10 @@ user_agents = dataset['train'].to_pandas()
21
  user_agents = user_agents.iloc[:,1:]
22
  user_batch = user_agents[:10]
23
 
 
 
 
 
24
  def create_description(row):
25
  description = (
26
  f"Imagine that you are currently {int(row['age'])} years old. You have {int(row['num_pets'])} pets "
@@ -43,10 +48,8 @@ question = (
43
  )
44
 
45
  def query_agent(description, question, image0, image1):
46
- image0_path = os.path.join(image_directory, image0)
47
- image1_path = os.path.join(image_directory, image1)
48
- base64_image0 = encode_image(image0_path)
49
- base64_image1 = encode_image(image1_path)
50
 
51
  payload = {
52
  "model": "gpt-4-vision-preview",
 
3
  import csv
4
  import requests
5
  import time
6
+ import base64
7
  import pandas as pd
8
  import openai
9
  from openai import OpenAI
 
22
  user_agents = user_agents.iloc[:,1:]
23
  user_batch = user_agents[:10]
24
 
25
+ def encode_image(image_path):
26
+ with open(image_path, "rb") as image_file:
27
+ return base64.b64encode(image_file.read()).decode('utf-8')
28
+
29
  def create_description(row):
30
  description = (
31
  f"Imagine that you are currently {int(row['age'])} years old. You have {int(row['num_pets'])} pets "
 
48
  )
49
 
50
  def query_agent(description, question, image0, image1):
51
+ base64_image0 = encode_image(image0)
52
+ base64_image1 = encode_image(image1)
 
 
53
 
54
  payload = {
55
  "model": "gpt-4-vision-preview",