Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,16 +10,7 @@ DEFAULT_PARAMS = {
|
|
| 10 |
"do_sample": False,
|
| 11 |
"max_new_tokens": 256,
|
| 12 |
}
|
| 13 |
-
DEFAULT_QUERY =
|
| 14 |
-
"Provide a factual description of this image in up to two paragraphs. "
|
| 15 |
-
"Include details on objects, background, scenery, interactions, gestures, poses, and any visible text content. "
|
| 16 |
-
"Specify the number of repeated objects. "
|
| 17 |
-
"Describe the dominant colors, color contrasts, textures, and materials. "
|
| 18 |
-
"Mention the composition, including the arrangement of elements and focus points. "
|
| 19 |
-
"Note the camera angle or perspective, and provide any identifiable contextual information. "
|
| 20 |
-
"Include details on the style, lighting, and shadows. "
|
| 21 |
-
"Avoid subjective interpretations or speculation."
|
| 22 |
-
)
|
| 23 |
|
| 24 |
DTYPE = torch.bfloat16
|
| 25 |
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
@@ -63,7 +54,7 @@ def generate_caption(
|
|
| 63 |
result = result.replace("This image showcases", "").strip().removesuffix("</s>").strip().capitalize()
|
| 64 |
return result
|
| 65 |
|
| 66 |
-
# CSS for design enhancements with a
|
| 67 |
css = """
|
| 68 |
#container {
|
| 69 |
background-color: #f9f9f9;
|
|
@@ -74,7 +65,14 @@ css = """
|
|
| 74 |
max-width: 400px;
|
| 75 |
margin: auto;
|
| 76 |
}
|
| 77 |
-
#input_image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
margin-top: 15px;
|
| 79 |
border: 2px solid #333; /* Darker outline */
|
| 80 |
border-radius: 8px;
|
|
@@ -86,22 +84,23 @@ css = """
|
|
| 86 |
padding: 10px;
|
| 87 |
cursor: pointer;
|
| 88 |
transition: background-color 0.3s ease;
|
|
|
|
| 89 |
}
|
| 90 |
#run_button:hover {
|
| 91 |
background-color: #333; /* Slightly lighter on hover */
|
| 92 |
}
|
| 93 |
"""
|
| 94 |
|
| 95 |
-
# Gradio interface with vertical alignment
|
| 96 |
with gr.Blocks(css=css) as demo:
|
| 97 |
with gr.Column(elem_id="container"):
|
| 98 |
input_image = gr.Image(type="pil", elem_id="input_image")
|
| 99 |
-
run_button = gr.Button(value="Generate
|
| 100 |
output_caption = gr.Textbox(label="Generated Caption", show_copy_button=True, elem_id="output_caption")
|
| 101 |
|
| 102 |
run_button.click(
|
| 103 |
fn=generate_caption,
|
| 104 |
-
inputs=[input_image],
|
| 105 |
outputs=output_caption,
|
| 106 |
)
|
| 107 |
|
|
|
|
| 10 |
"do_sample": False,
|
| 11 |
"max_new_tokens": 256,
|
| 12 |
}
|
| 13 |
+
DEFAULT_QUERY = "Write a detailed caption for this image."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
DTYPE = torch.bfloat16
|
| 16 |
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
|
| 54 |
result = result.replace("This image showcases", "").strip().removesuffix("</s>").strip().capitalize()
|
| 55 |
return result
|
| 56 |
|
| 57 |
+
# CSS for design enhancements with a fixed image input bar and simplified query
|
| 58 |
css = """
|
| 59 |
#container {
|
| 60 |
background-color: #f9f9f9;
|
|
|
|
| 65 |
max-width: 400px;
|
| 66 |
margin: auto;
|
| 67 |
}
|
| 68 |
+
#input_image {
|
| 69 |
+
margin-top: 15px;
|
| 70 |
+
border: 2px solid #333; /* Darker outline */
|
| 71 |
+
border-radius: 8px;
|
| 72 |
+
height: 300px; /* Fixed height */
|
| 73 |
+
object-fit: contain; /* Ensure image fits within the fixed height */
|
| 74 |
+
}
|
| 75 |
+
#output_caption {
|
| 76 |
margin-top: 15px;
|
| 77 |
border: 2px solid #333; /* Darker outline */
|
| 78 |
border-radius: 8px;
|
|
|
|
| 84 |
padding: 10px;
|
| 85 |
cursor: pointer;
|
| 86 |
transition: background-color 0.3s ease;
|
| 87 |
+
margin-top: 15px;
|
| 88 |
}
|
| 89 |
#run_button:hover {
|
| 90 |
background-color: #333; /* Slightly lighter on hover */
|
| 91 |
}
|
| 92 |
"""
|
| 93 |
|
| 94 |
+
# Gradio interface with vertical alignment and fixed image input height
|
| 95 |
with gr.Blocks(css=css) as demo:
|
| 96 |
with gr.Column(elem_id="container"):
|
| 97 |
input_image = gr.Image(type="pil", elem_id="input_image")
|
| 98 |
+
run_button = gr.Button(value="Generate", elem_id="run_button")
|
| 99 |
output_caption = gr.Textbox(label="Generated Caption", show_copy_button=True, elem_id="output_caption")
|
| 100 |
|
| 101 |
run_button.click(
|
| 102 |
fn=generate_caption,
|
| 103 |
+
inputs=[input_image],
|
| 104 |
outputs=output_caption,
|
| 105 |
)
|
| 106 |
|