FengHou97 commited on
Commit
c04a40d
·
verified ·
1 Parent(s): cde631c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -29
app.py CHANGED
@@ -7,19 +7,19 @@ from dotenv import load_dotenv
7
  import google.generativeai as genai
8
  import os
9
 
10
- from openai import OpenAI
11
- client = OpenAI(api_key="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")
12
- import base64
13
 
14
- # Open the image file and encode it as a base64 string
15
- def encode_image(image_path):
16
- with open(image_path, "rb") as image_file:
17
- return base64.b64encode(image_file.read()).decode("utf-8")
18
 
19
- # load_dotenv()
20
- # GOOGLE_API_KEY = os.getenv("GOOGLE_API")
21
- # genai.configure(api_key=GOOGLE_API_KEY)
22
- # model_vision = genai.GenerativeModel('gemini-pro-vision')
23
 
24
  def gemini_response_vision(input_texts, image):
25
  try:
@@ -68,26 +68,26 @@ def shot(image, labels_text, model_name, hypothesis_template_prefix, hypothesis_
68
  domains = [domain.strip(" ") for domain in domains_text.strip(" ").split(",")]
69
  else:
70
  #img = Image.open(image)
71
- #input_text = "Please describe the image from six dimensions, including weather (clear, sandstorm, foggy, rainy, snowy), angle (front, left, top), time (daytime, night), occlusion (unoccluded, lightly-occluded, partially-occluded, moderately-occluded, heavily-occluded), season (spring-summer, autumn, winter). Each dimension should be described in no more than 4 words and should match the image content. Please try to output from the options in the previous brackets. If there is no suitable result, output N/A."# Please also output a probability of your inference."# If there is no information in a certain dimension, you can directly output no information.
72
- #domains = gemini_response_vision(input_texts=input_text, image=image)
73
  #IMAGE_PATH = './reasoning_xy.jpg'
74
- base64_image = encode_image('car.png')
75
- prompt = "Please describe the image from six dimensions, including weather (clear, sandstorm, foggy, rainy, snowy), angle (front, left, top), time (daytime, night), occlusion (unoccluded, lightly-occluded, partially-occluded, moderately-occluded, heavily-occluded), season (spring-summer, autumn, winter). Each dimension should be described in no more than 4 words and should match the image content. Please try to output from the options in the previous brackets. If there is no suitable result, output N/A."# Please also output a probability of your inference."# If there is no information in a certain dimension, you can directly output no information."
76
 
77
- response = client.chat.completions.create(
78
- model="gpt-4o",
79
- messages=[
80
- # {"role": "system", "content": "You are a helpful assistant that responds in Markdown. Help me with my math homework!"},
81
- {"role": "user", "content": [
82
- {"type": "text", "text": prompt},
83
- {"type": "image_url", "image_url": {
84
- "url": f"data:image/png;base64,{base64_image}"}
85
- }
86
- ]}
87
- ],
88
- temperature=0.0,
89
- )
90
- domains = response.choices[0].message.content
91
  print(domains)
92
 
93
  hypothesis_template = hypothesis_template_prefix + ' ' + hypothesis_template_suffix.format(*domains)
 
7
  import google.generativeai as genai
8
  import os
9
 
10
+ # from openai import OpenAI
11
+ # client = OpenAI(api_key="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")
12
+ # import base64
13
 
14
+ # # Open the image file and encode it as a base64 string
15
+ # def encode_image(image_path):
16
+ # with open(image_path, "rb") as image_file:
17
+ # return base64.b64encode(image_file.read()).decode("utf-8")
18
 
19
+ load_dotenv()
20
+ GOOGLE_API_KEY = os.getenv("AIzaSyByqW3ByYPxC4xLS_NhgwAOAMMEgB7DvoY")
21
+ genai.configure(api_key=GOOGLE_API_KEY)
22
+ model_vision = genai.GenerativeModel('gemini-pro-vision')
23
 
24
  def gemini_response_vision(input_texts, image):
25
  try:
 
68
  domains = [domain.strip(" ") for domain in domains_text.strip(" ").split(",")]
69
  else:
70
  #img = Image.open(image)
71
+ input_text = "Please describe the image from six dimensions, including weather (clear, sandstorm, foggy, rainy, snowy), angle (front, left, top), time (daytime, night), occlusion (unoccluded, lightly-occluded, partially-occluded, moderately-occluded, heavily-occluded), season (spring-summer, autumn, winter). Each dimension should be described in no more than 4 words and should match the image content. Please try to output from the options in the previous brackets. If there is no suitable result, output N/A."# Please also output a probability of your inference."# If there is no information in a certain dimension, you can directly output no information.
72
+ domains = gemini_response_vision(input_texts=input_text, image=image)
73
  #IMAGE_PATH = './reasoning_xy.jpg'
74
+ # base64_image = encode_image('car.png')
75
+ # prompt = "Please describe the image from six dimensions, including weather (clear, sandstorm, foggy, rainy, snowy), angle (front, left, top), time (daytime, night), occlusion (unoccluded, lightly-occluded, partially-occluded, moderately-occluded, heavily-occluded), season (spring-summer, autumn, winter). Each dimension should be described in no more than 4 words and should match the image content. Please try to output from the options in the previous brackets. If there is no suitable result, output N/A."# Please also output a probability of your inference."# If there is no information in a certain dimension, you can directly output no information."
76
 
77
+ # response = client.chat.completions.create(
78
+ # model="gpt-4o",
79
+ # messages=[
80
+ # # {"role": "system", "content": "You are a helpful assistant that responds in Markdown. Help me with my math homework!"},
81
+ # {"role": "user", "content": [
82
+ # {"type": "text", "text": prompt},
83
+ # {"type": "image_url", "image_url": {
84
+ # "url": f"data:image/png;base64,{base64_image}"}
85
+ # }
86
+ # ]}
87
+ # ],
88
+ # temperature=0.0,
89
+ # )
90
+ # domains = response.choices[0].message.content
91
  print(domains)
92
 
93
  hypothesis_template = hypothesis_template_prefix + ' ' + hypothesis_template_suffix.format(*domains)