vsrinivas commited on
Commit
79f0f31
·
verified ·
1 Parent(s): d57358c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -13
app.py CHANGED
@@ -28,36 +28,40 @@ def process_image(input_type, image_url, image_upload, text):
28
  cmnt = "and is not that great. Try again"
29
  elif itm_score <= .75:
30
  cmnt = "and is good. But you can improve it. Try again"
31
- elif itm_score == 1.0:
32
- cmnt = "That is unbelievable. You have achieved the perfect score. Congratulations."
33
  else:
34
  cmnt = "and is excellent. Can you improve on it?"
35
-
36
  formatted_text = (
37
- f"""<div style='text-align: center; font-size: 40px; color: blue;'>
38
- Your description score is <span style='font-size: 60px; color: orange;'>{itm_score*100:.2f}/100</span> {cmnt}
39
- </div>"""
40
  )
41
  return formatted_text
42
 
 
 
 
 
 
 
43
  def toggle_inputs(input_type):
44
  if input_type == "URL":
45
- return gr.update(visible=True), gr.update(visible=False), gr.update(visible=True)
46
  else:
47
- return gr.update(visible=False), gr.update(visible=True), gr.update(visible=True)
48
 
49
  with gr.Blocks() as demo:
50
  input_type = gr.Radio(choices=["URL", "Upload"], label="Input Type")
51
  image_url = gr.Textbox(label="Image URL", visible=False)
 
52
  image_upload = gr.Image(type="pil", label="Upload Image", visible=False)
53
  description = gr.Textbox(label="Describe the image", visible=False, lines=3)
54
-
55
- input_type.change(fn=toggle_inputs, inputs=input_type, outputs=[image_url, image_upload, description])
56
 
 
 
 
57
  submit_btn = gr.Button("Submit")
58
  processed_image = gr.HTML(label="Your challenge result")
59
-
60
  submit_btn.click(fn=process_image, inputs=[input_type, image_url, image_upload, description], outputs=processed_image)
61
 
62
-
63
- demo.launch(share=True, debug=True)
 
28
  cmnt = "and is not that great. Try again"
29
  elif itm_score <= .75:
30
  cmnt = "and is good. But you can improve it. Try again"
 
 
31
  else:
32
  cmnt = "and is excellent. Can you improve on it?"
33
+
34
  formatted_text = (
35
+ f"""<div style='text-align: center; font-size: 40px; color: blue;'><h1>
36
+ Your decription score is <span style='font-size: 60px; color: orange;'>{itm_score*100:.2f}/100</span>; {cmnt}
37
+ </h1></div>"""
38
  )
39
  return formatted_text
40
 
41
+ def display_image_from_url(image_url):
42
+ if image_url:
43
+ image = Image.open(requests.get(image_url, stream=True).raw).convert('RGB')
44
+ return image
45
+ return None
46
+
47
  def toggle_inputs(input_type):
48
  if input_type == "URL":
49
+ return gr.update(visible=True), gr.update(visible=True), gr.update(visible=False), gr.update(visible=True)
50
  else:
51
+ return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), gr.update(visible=True)
52
 
53
  with gr.Blocks() as demo:
54
  input_type = gr.Radio(choices=["URL", "Upload"], label="Input Type")
55
  image_url = gr.Textbox(label="Image URL", visible=False)
56
+ url_image = gr.Image(type="pil", label="URL Image", visible=False)
57
  image_upload = gr.Image(type="pil", label="Upload Image", visible=False)
58
  description = gr.Textbox(label="Describe the image", visible=False, lines=3)
 
 
59
 
60
+ input_type.change(fn=toggle_inputs, inputs=input_type, outputs=[image_url, url_image, image_upload, description])
61
+ image_url.change(fn=display_image_from_url, inputs=image_url, outputs=url_image)
62
+
63
  submit_btn = gr.Button("Submit")
64
  processed_image = gr.HTML(label="Your challenge result")
 
65
  submit_btn.click(fn=process_image, inputs=[input_type, image_url, image_upload, description], outputs=processed_image)
66
 
67
+ demo.launch(debug=True, share=True)