arjunanand13 commited on
Commit
8ea3c0d
·
verified ·
1 Parent(s): a7a1792

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceApi
3
+
4
+ api_token = "your_huggingface_api_token"
5
+ client = InferenceApi("HuggingFaceM4/idefics2-8b", api_token=api_token)
6
+
7
+ def model_inference(image, text):
8
+ inputs = {
9
+ "inputs": {
10
+ "text": text,
11
+ "image": image
12
+ }
13
+ }
14
+
15
+ result = client(inputs)
16
+
17
+ generated_text = result['generated_text']
18
+ return generated_text
19
+
20
+ 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:
21
+ gr.Markdown("## Enhanced IDEFICS2 Demo")
22
+ with gr.Row():
23
+ with gr.Column(scale=1):
24
+ image_input = gr.Image(label="Upload Image", type="file", tool="editor", height=480, width=640)
25
+ query_input = gr.Textbox(label="Enter Prompt", placeholder="Type your prompt here...")
26
+ with gr.Column(scale=1):
27
+ output = gr.Textbox(label="Model Output", interactive=True, placeholder="Output will be displayed here...")
28
+
29
+ submit_btn = gr.Button("Generate")
30
+ submit_btn.click(model_inference, inputs=[image_input, query_input], outputs=output)
31
+
32
+ examples = [
33
+ ["example_images/american_football.png", "Explain in detail what is depicted in the picture"],
34
+ ["example_images/bike.png", "Explore the image closely and describe in detail what you discover."],
35
+ ["example_images/finance.png", "Provide a detailed description of everything you see in the image."],
36
+ ["example_images/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."],
37
+ ["example_images/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."]
38
+ ]
39
+ gr.Examples(examples=examples, inputs=[image_input, query_input], outputs=output)
40
+
41
+ demo.launch(debug=True)