mjavaid commited on
Commit
7bd22d1
·
1 Parent(s): 38746a1

first commit

Browse files
Files changed (1) hide show
  1. app.py +16 -16
app.py CHANGED
@@ -30,26 +30,27 @@ def process_image_and_prompt(uploaded_image, image_url, prompt, temperature=0.3,
30
  return "Model failed to load. Please check the logs."
31
 
32
  # Determine which image input to use:
33
- # If an image is uploaded, convert its file path to a URL.
34
  if uploaded_image:
35
- # Gradio returns a file path; if it doesn't start with "http", prefix it so that it is served.
36
- img_url = uploaded_image if str(uploaded_image).startswith("http") else f"/file/{uploaded_image}"
 
 
 
 
 
 
37
  elif image_url and image_url.strip():
 
38
  img_url = image_url.strip()
39
- else:
40
- return "Please provide either an image upload or an image URL."
41
-
42
- # Build the message using the Aya Vision chat template.
43
- # Note: Aya Vision requires the image to be sent as a URL.
44
- messages = [
45
- {
46
  "role": "user",
47
  "content": [
48
  {"type": "image", "url": img_url},
49
  {"type": "text", "text": prompt},
50
  ],
51
- },
52
- ]
 
53
 
54
  try:
55
  inputs = processor.apply_chat_template(
@@ -88,16 +89,15 @@ with gr.Blocks(title="Aya Vision 8B Demo") as demo:
88
  gr.Markdown("# Aya Vision 8B Model Demo")
89
  gr.Markdown(
90
  """
91
- This app demonstrates the C4AI Aya Vision 8B model, which requires an image URL as input.
92
- You can either upload an image (it will be served as a URL) or provide a direct image URL.
93
- Enter a prompt along with the image to get started!
94
  """
95
  )
96
  gr.Markdown(f"**Model Status:** {model_status}")
97
 
98
  gr.Markdown("### Provide an Image")
99
  with gr.Tab("Upload Image"):
100
- # Using type="filepath" returns the local file path which is then converted into a URL.
101
  image_upload = gr.Image(label="Upload Image", type="filepath")
102
  with gr.Tab("Image URL"):
103
  image_url_input = gr.Textbox(label="Image URL", placeholder="Enter a direct image URL")
 
30
  return "Model failed to load. Please check the logs."
31
 
32
  # Determine which image input to use:
 
33
  if uploaded_image:
34
+ # If an image is uploaded, use the image directly.
35
+ messages = [{
36
+ "role": "user",
37
+ "content": [
38
+ {"type": "image", "image": uploaded_image},
39
+ {"type": "text", "text": prompt},
40
+ ],
41
+ }]
42
  elif image_url and image_url.strip():
43
+ # Otherwise, use the provided image URL.
44
  img_url = image_url.strip()
45
+ messages = [{
 
 
 
 
 
 
46
  "role": "user",
47
  "content": [
48
  {"type": "image", "url": img_url},
49
  {"type": "text", "text": prompt},
50
  ],
51
+ }]
52
+ else:
53
+ return "Please provide either an image upload or an image URL."
54
 
55
  try:
56
  inputs = processor.apply_chat_template(
 
89
  gr.Markdown("# Aya Vision 8B Model Demo")
90
  gr.Markdown(
91
  """
92
+ This app demonstrates the C4AI Aya Vision 8B model. You can either upload an image (which will be sent directly)
93
+ or provide a direct image URL. Enter a prompt along with the image to get started!
 
94
  """
95
  )
96
  gr.Markdown(f"**Model Status:** {model_status}")
97
 
98
  gr.Markdown("### Provide an Image")
99
  with gr.Tab("Upload Image"):
100
+ # Using type="filepath" returns the local file path which is then passed directly.
101
  image_upload = gr.Image(label="Upload Image", type="filepath")
102
  with gr.Tab("Image URL"):
103
  image_url_input = gr.Textbox(label="Image URL", placeholder="Enter a direct image URL")