cutiee82 commited on
Commit
63d7e75
·
verified ·
1 Parent(s): f81830f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -15,7 +15,7 @@ def image_to_base64(image):
15
  buf.seek(0)
16
  return base64.b64encode(buf.getvalue()).decode("utf-8")
17
 
18
- def caption(image):
19
  image = image_to_base64(image)
20
  return client.chat.completions.create(
21
  model="openai-large",
@@ -27,7 +27,7 @@ def caption(image):
27
  "type": "image_url",
28
  "image_url": {"url": f"data:image/jpeg;base64,{image}"}
29
  },
30
- {"type": "text", "text": PROMPT}
31
  ]
32
  }
33
  ],
@@ -36,6 +36,10 @@ def caption(image):
36
 
37
  gr.Interface(
38
  caption,
39
- inputs=gr.Image(type="pil", label="Image"),
40
- outputs=gr.Textbox(label="Caption")
 
 
 
 
41
  ).launch(debug=True)
 
15
  buf.seek(0)
16
  return base64.b64encode(buf.getvalue()).decode("utf-8")
17
 
18
+ def caption(image, prompt):
19
  image = image_to_base64(image)
20
  return client.chat.completions.create(
21
  model="openai-large",
 
27
  "type": "image_url",
28
  "image_url": {"url": f"data:image/jpeg;base64,{image}"}
29
  },
30
+ {"type": "text", "text": prompt}
31
  ]
32
  }
33
  ],
 
36
 
37
  gr.Interface(
38
  caption,
39
+ inputs=[
40
+ gr.Image(type="pil", label="Image"),
41
+ gr.Textbox(label="Prompt", value=PROMPT)
42
+ ],
43
+ outputs=gr.Textbox(label="Caption"),
44
+ title="Image Captioning"
45
  ).launch(debug=True)