Akshayram1 commited on
Commit
10484b0
·
verified ·
1 Parent(s): 8b61647

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -7,21 +7,23 @@ import pytesseract
7
  from PIL import Image
8
  import io
9
  import numpy as np
 
10
 
11
  # Define the LiteLLMModel with OpenAI key
12
  model = LiteLLMModel(model_id="gpt-4o", api_key="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")
13
 
14
  @tool
15
- def extract_components(image_data: bytes) -> str:
16
  """
17
  Extract components from a web design image.
18
 
19
  Args:
20
- image_data: The image data in bytes.
21
 
22
  Returns:
23
  A string describing the components found in the image.
24
  """
 
25
  image = Image.open(io.BytesIO(image_data))
26
  gray = cv2.cvtColor(np.array(image), cv2.COLOR_BGR2GRAY)
27
  components = pytesseract.image_to_string(gray)
@@ -54,8 +56,9 @@ uploaded_file = st.file_uploader("Upload a web design image", type=["png", "jpg"
54
  if st.button("Extract and Generate Code"):
55
  if uploaded_file is not None:
56
  image_data = uploaded_file.read()
57
- components = agent.run("extract_components", image_data=image_data)
58
- code = agent.run("generate_code", components=components)
 
59
  st.write("Extracted Components:", components)
60
  st.write("Generated Code:", code)
61
  else:
 
7
  from PIL import Image
8
  import io
9
  import numpy as np
10
+ import base64
11
 
12
  # Define the LiteLLMModel with OpenAI key
13
  model = LiteLLMModel(model_id="gpt-4o", api_key="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")
14
 
15
  @tool
16
+ def extract_components(image_data_base64: str) -> str:
17
  """
18
  Extract components from a web design image.
19
 
20
  Args:
21
+ image_data_base64: The image data in base64 string format.
22
 
23
  Returns:
24
  A string describing the components found in the image.
25
  """
26
+ image_data = base64.b64decode(image_data_base64)
27
  image = Image.open(io.BytesIO(image_data))
28
  gray = cv2.cvtColor(np.array(image), cv2.COLOR_BGR2GRAY)
29
  components = pytesseract.image_to_string(gray)
 
56
  if st.button("Extract and Generate Code"):
57
  if uploaded_file is not None:
58
  image_data = uploaded_file.read()
59
+ image_data_base64 = base64.b64encode(image_data).decode('utf-8')
60
+ components = agent.run(f"extract_components {image_data_base64}")
61
+ code = agent.run(f"generate_code {components}")
62
  st.write("Extracted Components:", components)
63
  st.write("Generated Code:", code)
64
  else: