CGQN's picture
Update app.py
30886de verified
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()