File size: 3,272 Bytes
8740f94
 
 
 
98a9e83
8740f94
98a9e83
8740f94
 
0d71964
8740f94
 
0d71964
8740f94
 
 
0d71964
8740f94
c954c3d
8740f94
 
0d71964
8740f94
0d71964
8740f94
0d71964
8740f94
 
 
c954c3d
98a9e83
c954c3d
 
 
 
 
 
98a9e83
8740f94
 
a38f21e
8740f94
 
 
 
 
30886de
 
 
98a9e83
0d71964
 
 
98a9e83
 
0d71964
98a9e83
0d71964
8740f94
 
0d71964
30886de
 
 
8740f94
 
 
0d71964
8740f94
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import time
import gradio as gr
from PIL import Image

# Added more placeholder responses to prevent an IndexError
PREWRITTEN_RESPONSES = [
    "When it comes to retailing industry, we often remind the both part of realistic store and internet shopping. Both of them are all have their pros and cons, but according to the picture, we can find out both of the internet sales counting and its profit are all growed up every year between twenty eighteen to twenty twenty one. The years () rate began with twenty eighteen only 10.3%, next year 14.1%, and the next 20.3%, finally finished in twenty twenty one up to 24.5%. The sales profit also began with twenty eighteen only 2517 (million), next year 2893, and the next 3456, finally finished in twenty twenty one up to 4303. Therefore, we can find out the internet shopping is growed up between the four years. Begun 2019, according my observed,  () more of my friends change to internet shopping because of COVID-19. All above the results provided the picture is the realistic.\nIn my opinion, shopping on the internet can save many times to me, so I also do it when I"
]

def fake_minicpm_infer(image: Image.Image, text: str):
    """
    Simulate a MiniCPM-V-4_5 inference:
    - Sleep for a fixed duration to mimic model loading & generation latency.
    - Return a prewritten response based on simple heuristics of input.
    """
    if image is None and not text.strip():
        return "Please provide an image or text to start the demo."

    time.sleep(8.5) # Simulate inference time

    t = text.lower().strip()
    if any(k in t for k in ["travel", "advice", "safety", "suggestion"]):
        return PREWRITTEN_RESPONSES[1]
    if any(k in t for k in ["weather", "rain", "wind", "cloud"]):
        return PREWRITTEN_RESPONSES[2]
    if any(k in t for k in ["photography", "camera", "photo", "shoot"]):
        return PREWRITTEN_RESPONSES[3]
    return PREWRITTEN_RESPONSES[0]

custom_css = """
#input_textbox textarea, 
#output_textbox textarea {
    font-size: 18px !important;
}
"""

with gr.Blocks(title="MiniCPM-V-4_5 Demo", css=custom_css) as demo:

    gr.Markdown(
        """
        # MiniCPM-V-4_5 Demo
        """
    )

    with gr.Row():
        with gr.Column(scale=1):
            # --- MODIFICATION 1 ---
            # Set the maximum display height of the image component to 800px.
            image_in = gr.Image(label="Input Image", type="pil", height=800)
            
            text_in = gr.Textbox(
                label="Input Question/Description",
                placeholder="e.g., What kind of landscape is this? or What should I be aware of when traveling?",
                lines=3,
                elem_id="input_textbox" 
            )
            
            submit_btn = gr.Button("Submit", variant="primary")

        with gr.Column(scale=1):
            gr.Markdown("### Output")
            # --- MODIFICATION 2 ---
            # Increased the number of lines to 12 (original 8 * 1.5).
            output = gr.Textbox(label="Model Response", lines=12, elem_id="output_textbox")

    submit_btn.click(
        fn=fake_minicpm_infer,
        inputs=[image_in, text_in],
        outputs=output,
        api_name="mock_infer"
    )

if __name__ == "__main__":
    demo.launch()