capradeepgujaran commited on
Commit
ef42063
·
verified ·
1 Parent(s): 3b1dafd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -26,16 +26,12 @@ def analyze_construction_image(image):
26
  completion = client.chat.completions.create(
27
  model="llama-3.2-11b-vision-preview",
28
  messages=[
29
- {
30
- "role": "system",
31
- "content": "You are an AI assistant specialized in analyzing construction site images. Identify issues, categorize them, and provide steps to resolve them."
32
- },
33
  {
34
  "role": "user",
35
  "content": [
36
  {
37
  "type": "text",
38
- "text": "Analyze this construction image. Identify the snag category, provide a detailed snag description, and list steps to desnag."
39
  },
40
  {
41
  "type": "image_url",
@@ -47,7 +43,7 @@ def analyze_construction_image(image):
47
  }
48
  ],
49
  temperature=0.7,
50
- max_tokens=300,
51
  top_p=1,
52
  stream=False,
53
  stop=None
@@ -56,10 +52,17 @@ def analyze_construction_image(image):
56
  result = completion.choices[0].message.content
57
 
58
  # Parse the result
59
- lines = result.split('\n')
60
- snag_category = lines[0] if len(lines) > 0 else "N/A"
61
- snag_description = lines[1] if len(lines) > 1 else "N/A"
62
- desnag_steps = "\n".join(lines[2:]) if len(lines) > 2 else "N/A"
 
 
 
 
 
 
 
63
 
64
  return snag_category, snag_description, desnag_steps
65
  except Exception as e:
 
26
  completion = client.chat.completions.create(
27
  model="llama-3.2-11b-vision-preview",
28
  messages=[
 
 
 
 
29
  {
30
  "role": "user",
31
  "content": [
32
  {
33
  "type": "text",
34
+ "text": "You are an AI assistant specialized in analyzing construction site images. Analyze this construction image. Identify the snag category, provide a detailed snag description, and list steps to desnag. Format your response as follows:\nSnag Category: [category]\nSnag Description: [detailed description]\nSteps to Desnag:\n1. [step 1]\n2. [step 2]\n3. [step 3]"
35
  },
36
  {
37
  "type": "image_url",
 
43
  }
44
  ],
45
  temperature=0.7,
46
+ max_tokens=500,
47
  top_p=1,
48
  stream=False,
49
  stop=None
 
52
  result = completion.choices[0].message.content
53
 
54
  # Parse the result
55
+ snag_category = "N/A"
56
+ snag_description = "N/A"
57
+ desnag_steps = "N/A"
58
+
59
+ for line in result.split('\n'):
60
+ if line.startswith("Snag Category:"):
61
+ snag_category = line.split(":", 1)[1].strip()
62
+ elif line.startswith("Snag Description:"):
63
+ snag_description = line.split(":", 1)[1].strip()
64
+ elif line.startswith("Steps to Desnag:"):
65
+ desnag_steps = "\n".join(result.split("Steps to Desnag:")[1].strip().split("\n"))
66
 
67
  return snag_category, snag_description, desnag_steps
68
  except Exception as e: