gizemsarsinlar commited on
Commit
9f684be
·
verified ·
1 Parent(s): 2b49fb1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -4
app.py CHANGED
@@ -25,8 +25,7 @@ def get_model_and_processor(model_id):
25
  )
26
  return model, processor
27
 
28
- # Modified the spaces.GPU decorator usage
29
- @spaces.GPU(memory=30) # Specify the GPU memory requirement in GB
30
  def run_example(image, text_input=None, model_id=model_name):
31
  model, processor = get_model_and_processor(model_id)
32
  prompt = f"{user_prompt}<|image_1|>\n{text_input}{prompt_suffix}{assistant_prompt}"
@@ -46,7 +45,48 @@ def run_example(image, text_input=None, model_id=model_name):
46
  )[0]
47
  return response
48
 
49
- # Rest of your code remains the same until demo.launch()
 
 
 
 
 
 
50
 
51
- # Modified launch parameters
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  demo.launch(share=True, server_name="0.0.0.0")
 
25
  )
26
  return model, processor
27
 
28
+ @spaces.GPU(memory=30)
 
29
  def run_example(image, text_input=None, model_id=model_name):
30
  model, processor = get_model_and_processor(model_id)
31
  prompt = f"{user_prompt}<|image_1|>\n{text_input}{prompt_suffix}{assistant_prompt}"
 
45
  )[0]
46
  return response
47
 
48
+ css = """
49
+ #output {
50
+ height: 500px;
51
+ overflow: auto;
52
+ border: 1px solid #ccc;
53
+ }
54
+ """
55
 
56
+ # Create the Gradio interface
57
+ demo = gr.Blocks(css=css)
58
+
59
+ with demo:
60
+ gr.Markdown("## Phi-3.5 Vision Instruct Demo with Example Inputs")
61
+
62
+ with gr.Tab(label="Phi-3.5 Input"):
63
+ with gr.Row():
64
+ with gr.Column():
65
+ input_img = gr.Image(label="Input Picture")
66
+ model_selector = gr.Dropdown(
67
+ choices=[model_name],
68
+ label="Model",
69
+ value=model_name
70
+ )
71
+ text_input = gr.Textbox(label="Question")
72
+ submit_btn = gr.Button(value="Submit")
73
+ with gr.Column():
74
+ output_text = gr.Textbox(label="Output Text")
75
+
76
+ examples = [
77
+ ["image1.jpeg", "What does this painting tell us explain in detail?"],
78
+ ["image2.jpg", "What does this painting tell us explain in detail?"],
79
+ ["image3.jpg", "Describe the scene in this picture."]
80
+ ]
81
+
82
+ gr.Examples(
83
+ examples=examples,
84
+ inputs=[input_img, text_input],
85
+ examples_per_page=3
86
+ )
87
+
88
+ submit_btn.click(run_example, [input_img, text_input, model_selector], [output_text])
89
+
90
+ # Queue and launch the demo
91
+ demo.queue()
92
  demo.launch(share=True, server_name="0.0.0.0")