arjunanand13 commited on
Commit
4d44c1d
·
verified ·
1 Parent(s): cd84313

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -11
app.py CHANGED
@@ -72,25 +72,59 @@ def model_inference(image, text):
72
  generated_text = result['generated_text']
73
  return generated_text
74
 
75
- with gr.Blocks(css=".input_image {max-width: 100%; border: 1px solid #ccc; box-shadow: 0 0 10px #ccc; margin-bottom: 10px;} .output_textbox {min-height: 100px;}") as demo:
 
 
 
 
76
  gr.Markdown("## Enhanced IDEFICS2 Demo")
 
 
77
  with gr.Row():
78
- with gr.Column(scale=1):
79
- image_input = gr.Image(label="Upload Image", type="pil", height=240, width=320)
80
- query_input = gr.Textbox(label="Enter Prompt", placeholder="Type your prompt here...")
81
- with gr.Column(scale=1):
82
- output = gr.Textbox(label="Model Output", interactive=True, placeholder="Output will be displayed here...")
83
-
 
 
 
84
  submit_btn = gr.Button("Generate")
85
  submit_btn.click(model_inference, inputs=[image_input, query_input], outputs=output)
86
 
 
87
  examples = [
88
  ["american_football.png", "Explain in detail what is depicted in the picture"],
89
- ["bike.png", "Explore the image closely and describe in detail what you discover."],
90
- ["finance.png", "Provide a detailed description of everything you see in the image."],
91
- ["science.png", "Please perform optical character recognition (OCR) on the uploaded image. Extract all text visible in the image accurately. Ensure to capture the text in its entirety and maintain the formatting as closely as possible to how it appears in the image. After extracting the text, display it in a clear and readable format, making sure that any special characters or symbols are also accurately represented. Provide the extracted text as output."],
92
- ["spirituality.png", "Please perform optical character recognition (OCR) on the uploaded image. Extract all text visible in the image accurately. Ensure to capture the text in its entirety and maintain the formatting as closely as possible to how it appears in the image. After extracting the text, display it in a clear and readable format, making sure that any special characters or symbols are also accurately represented. Provide the extracted text as output."]
93
  ]
94
  gr.Examples(examples=examples, inputs=[image_input, query_input], outputs=output)
95
 
 
96
  demo.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  generated_text = result['generated_text']
73
  return generated_text
74
 
75
+ with gr.Blocks(css="""
76
+ .input_image, .prompt_input {
77
+ background-color: lightgrey;
78
+ }
79
+ """) as demo:
80
  gr.Markdown("## Enhanced IDEFICS2 Demo")
81
+
82
+ # Create a row with two columns of equal size
83
  with gr.Row():
84
+ with gr.Column():
85
+ # Labelled input fields
86
+ image_input = gr.Image(label="Upload Image", type="pil", elem_classes=["input_image"]) #,height=240, width=320
87
+ query_input = gr.Textbox(label="Enter Prompt", placeholder="Type your prompt here...", elem_classes=["prompt_input"])
88
+ with gr.Column():
89
+ # Output textbox
90
+ output = gr.Textbox(label="Model Output", interactive=True, placeholder="Output will be displayed here...", elem_classes=["prompt_input"])
91
+
92
+ # Button to submit the inputs for model inference
93
  submit_btn = gr.Button("Generate")
94
  submit_btn.click(model_inference, inputs=[image_input, query_input], outputs=output)
95
 
96
+ # Example inputs for quick testing
97
  examples = [
98
  ["american_football.png", "Explain in detail what is depicted in the picture"],
99
+ ["bike.png", "Describe in detail what you see in this image."],
100
+ ["finance.png", "Describe in detail everything you see in the image."],
101
+ ["science.png", "Extract all visible text in the image, keeping the format."],
102
+ ["spirituality.png", "Extract all text from the image, preserving its format."]
103
  ]
104
  gr.Examples(examples=examples, inputs=[image_input, query_input], outputs=output)
105
 
106
+ # Launch the Gradio app with debugging enabled
107
  demo.launch(debug=True)
108
+
109
+ # with gr.Blocks(css=".input_image {max-width: 100%; border: 1px solid #ccc; box-shadow: 0 0 10px #ccc; margin-bottom: 10px;} .output_textbox {min-height: 100px;}") as demo:
110
+ # gr.Markdown("## Enhanced IDEFICS2 Demo")
111
+ # with gr.Row():
112
+ # with gr.Column(scale=1):
113
+ # image_input = gr.Image(label="Upload Image", type="pil", height=240, width=320)
114
+ # query_input = gr.Textbox(label="Enter Prompt", placeholder="Type your prompt here...")
115
+ # with gr.Column(scale=1):
116
+ # output = gr.Textbox(label="Model Output", interactive=True, placeholder="Output will be displayed here...")
117
+
118
+ # submit_btn = gr.Button("Generate")
119
+ # submit_btn.click(model_inference, inputs=[image_input, query_input], outputs=output)
120
+
121
+ # examples = [
122
+ # ["american_football.png", "Explain in detail what is depicted in the picture"],
123
+ # ["bike.png", "Explore the image closely and describe in detail what you discover."],
124
+ # ["finance.png", "Provide a detailed description of everything you see in the image."],
125
+ # ["science.png", "Please perform optical character recognition (OCR) on the uploaded image. Extract all text visible in the image accurately. Ensure to capture the text in its entirety and maintain the formatting as closely as possible to how it appears in the image. After extracting the text, display it in a clear and readable format, making sure that any special characters or symbols are also accurately represented. Provide the extracted text as output."],
126
+ # ["spirituality.png", "Please perform optical character recognition (OCR) on the uploaded image. Extract all text visible in the image accurately. Ensure to capture the text in its entirety and maintain the formatting as closely as possible to how it appears in the image. After extracting the text, display it in a clear and readable format, making sure that any special characters or symbols are also accurately represented. Provide the extracted text as output."]
127
+ # ]
128
+ # gr.Examples(examples=examples, inputs=[image_input, query_input], outputs=output)
129
+
130
+ # demo.launch(debug=True)