capradeepgujaran commited on
Commit
55c45f5
·
verified ·
1 Parent(s): f82c921

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -13,9 +13,15 @@ GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
13
  client = Groq(api_key=GROQ_API_KEY)
14
 
15
  def encode_image(image):
16
- buffered = io.BytesIO()
17
- image.save(buffered, format="PNG")
18
- return base64.b64encode(buffered.getvalue()).decode('utf-8')
 
 
 
 
 
 
19
 
20
  def analyze_construction_image(image, follow_up_question=""):
21
  if image is None:
@@ -49,7 +55,7 @@ def analyze_construction_image(image, follow_up_question=""):
49
  })
50
 
51
  completion = client.chat.completions.create(
52
- model="llama-3.2-11b-vision-preview",
53
  messages=messages,
54
  temperature=0.7,
55
  max_tokens=1000,
@@ -87,7 +93,7 @@ iface = gr.Interface(
87
  ["example_image1.jpg", "What safety concerns do you see?"],
88
  ["example_image2.jpg", "Is there any visible structural damage?"]
89
  ],
90
- cache_examples=True,
91
  theme="default"
92
  )
93
 
 
13
  client = Groq(api_key=GROQ_API_KEY)
14
 
15
  def encode_image(image):
16
+ if isinstance(image, str): # If image is a file path
17
+ with open(image, "rb") as image_file:
18
+ return base64.b64encode(image_file.read()).decode('utf-8')
19
+ elif isinstance(image, Image.Image): # If image is a PIL Image
20
+ buffered = io.BytesIO()
21
+ image.save(buffered, format="PNG")
22
+ return base64.b64encode(buffered.getvalue()).decode('utf-8')
23
+ else:
24
+ raise ValueError("Unsupported image type")
25
 
26
  def analyze_construction_image(image, follow_up_question=""):
27
  if image is None:
 
55
  })
56
 
57
  completion = client.chat.completions.create(
58
+ model="llama-3.2-90b-vision-preview",
59
  messages=messages,
60
  temperature=0.7,
61
  max_tokens=1000,
 
93
  ["example_image1.jpg", "What safety concerns do you see?"],
94
  ["example_image2.jpg", "Is there any visible structural damage?"]
95
  ],
96
+ cache_examples=False, # Disable caching to avoid file moving issues
97
  theme="default"
98
  )
99