CGQN commited on
Commit
c954c3d
·
verified ·
1 Parent(s): c756d9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -24
app.py CHANGED
@@ -2,28 +2,26 @@ import time
2
  import gradio as gr
3
  from PIL import Image
4
 
5
- # MODIFIED: Translated the predefined responses to English
 
6
  PREWRITTEN_RESPONSES = [
7
- "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"
 
 
 
8
  ]
9
 
10
- # MODIFIED: Removed the simulate_seconds parameter from the function signature
11
  def fake_minicpm_infer(image: Image.Image, text: str):
12
  """
13
  Simulate a MiniCPM-V-4_5 inference:
14
  - Sleep for a fixed duration to mimic model loading & generation latency.
15
  - Return a prewritten response based on simple heuristics of input.
16
  """
17
- # Basic input validation
18
  if image is None and not text.strip():
19
- # MODIFIED: Translated the validation message
20
  return "Please provide an image or text to start the demo."
21
 
22
- # MODIFIED: Use a fixed sleep time instead of a parameter
23
- # Simulate heavy inference
24
- time.sleep(8.5)
25
 
26
- # Very simple heuristic to pick a response
27
  t = text.lower().strip()
28
  if any(k in t for k in ["travel", "advice", "safety", "suggestion"]):
29
  return PREWRITTEN_RESPONSES[1]
@@ -31,10 +29,23 @@ def fake_minicpm_infer(image: Image.Image, text: str):
31
  return PREWRITTEN_RESPONSES[2]
32
  if any(k in t for k in ["photography", "camera", "photo", "shoot"]):
33
  return PREWRITTEN_RESPONSES[3]
34
- # Default description
35
  return PREWRITTEN_RESPONSES[0]
36
 
37
- with gr.Blocks(title="MiniCPM-V-4_5 Demo") as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  gr.Markdown(
39
  """
40
  # MiniCPM-V-4_5 Demo
@@ -43,29 +54,20 @@ with gr.Blocks(title="MiniCPM-V-4_5 Demo") as demo:
43
 
44
  with gr.Row():
45
  with gr.Column(scale=1):
46
- # MODIFIED: Translated UI component labels and placeholders
47
  image_in = gr.Image(label="Input Image", type="pil")
48
  text_in = gr.Textbox(
49
  label="Input Question/Description",
50
  placeholder="e.g., What kind of landscape is this? or What should I be aware of when traveling?",
51
  lines=3
52
  )
53
-
54
- # MODIFIED: The Slider component has been removed
55
- # simulate_time = gr.Slider(
56
- # minimum=3, maximum=20, value=10, step=1, label="模拟推理时长(秒)",
57
- # info="不加载真实模型,仅模拟推理时间"
58
- # )
59
-
60
  submit_btn = gr.Button("Submit", variant="primary")
61
 
62
  with gr.Column(scale=1):
63
- # MODIFIED: Translated UI component labels
64
  gr.Markdown("### Output")
65
- output = gr.Textbox(label="Model Response", lines=8)
 
 
66
 
67
- # Best practice: bind events after components are created
68
- # MODIFIED: Removed simulate_time from the inputs list
69
  submit_btn.click(
70
  fn=fake_minicpm_infer,
71
  inputs=[image_in, text_in],
@@ -74,5 +76,4 @@ with gr.Blocks(title="MiniCPM-V-4_5 Demo") as demo:
74
  )
75
 
76
  if __name__ == "__main__":
77
- # Launch with share=True for quick remote access (optional)
78
  demo.launch()
 
2
  import gradio as gr
3
  from PIL import Image
4
 
5
+ # MODIFIED: Added more placeholder responses to prevent an IndexError,
6
+ # as the original function accesses indices 1, 2, and 3.
7
  PREWRITTEN_RESPONSES = [
8
+ "This is a sample response about a chart. It seems to describe the growth of internet shopping over a four-year period, from 2018 to 2021. The sales figures and growth rates are mentioned, showing a clear upward trend. The text also speculates that the COVID-19 pandemic might have contributed to this shift in consumer behavior.",
9
+ "Travel Advice: This is a placeholder for travel advice.",
10
+ "Weather Analysis: This is a placeholder for a weather analysis.",
11
+ "Photography Tips: This is a placeholder for photography tips."
12
  ]
13
 
 
14
  def fake_minicpm_infer(image: Image.Image, text: str):
15
  """
16
  Simulate a MiniCPM-V-4_5 inference:
17
  - Sleep for a fixed duration to mimic model loading & generation latency.
18
  - Return a prewritten response based on simple heuristics of input.
19
  """
 
20
  if image is None and not text.strip():
 
21
  return "Please provide an image or text to start the demo."
22
 
23
+ time.sleep(8.5) # Simulate inference time
 
 
24
 
 
25
  t = text.lower().strip()
26
  if any(k in t for k in ["travel", "advice", "safety", "suggestion"]):
27
  return PREWRITTEN_RESPONSES[1]
 
29
  return PREWRITTEN_RESPONSES[2]
30
  if any(k in t for k in ["photography", "camera", "photo", "shoot"]):
31
  return PREWRITTEN_RESPONSES[3]
 
32
  return PREWRITTEN_RESPONSES[0]
33
 
34
+ # --- START OF MODIFICATIONS ---
35
+
36
+ # Define custom CSS to increase the font size of our target textbox.
37
+ # We target the <textarea> element inside the component with the ID 'output_textbox'.
38
+ custom_css = """
39
+ #output_textbox textarea {
40
+ font-size: 18px !important;
41
+ }
42
+ """
43
+
44
+ # Pass the custom CSS to the gr.Blocks constructor.
45
+ with gr.Blocks(title="MiniCPM-V-4_5 Demo", css=custom_css) as demo:
46
+
47
+ # --- END OF MODIFICATIONS ---
48
+
49
  gr.Markdown(
50
  """
51
  # MiniCPM-V-4_5 Demo
 
54
 
55
  with gr.Row():
56
  with gr.Column(scale=1):
 
57
  image_in = gr.Image(label="Input Image", type="pil")
58
  text_in = gr.Textbox(
59
  label="Input Question/Description",
60
  placeholder="e.g., What kind of landscape is this? or What should I be aware of when traveling?",
61
  lines=3
62
  )
 
 
 
 
 
 
 
63
  submit_btn = gr.Button("Submit", variant="primary")
64
 
65
  with gr.Column(scale=1):
 
66
  gr.Markdown("### Output")
67
+ # --- MODIFICATION ---
68
+ # Add a unique element ID to the output textbox so we can target it with CSS.
69
+ output = gr.Textbox(label="Model Response", lines=8, elem_id="output_textbox")
70
 
 
 
71
  submit_btn.click(
72
  fn=fake_minicpm_infer,
73
  inputs=[image_in, text_in],
 
76
  )
77
 
78
  if __name__ == "__main__":
 
79
  demo.launch()