Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,68 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
def
|
| 4 |
-
return "Hello " + name + "!!"
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
def main():
|
|
|
|
| 4 |
|
| 5 |
+
def generate_predictions(image_input, text_input, do_sample, sampling_topp, sampling_temperature)
|
| 6 |
+
|
| 7 |
+
return None, None
|
| 8 |
+
|
| 9 |
+
term_of_use = """
|
| 10 |
+
### Terms of use
|
| 11 |
+
By using this model, users are required to agree to the following terms:
|
| 12 |
+
The model is intended for academic and research purposes.
|
| 13 |
+
The utilization of the model to create unsuitable material is strictly forbidden and not endorsed by this work.
|
| 14 |
+
The accountability for any improper or unacceptable application of the model rests exclusively with the individuals who generated such content.
|
| 15 |
+
|
| 16 |
+
### License
|
| 17 |
+
This project is licensed under the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct).
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
with gr.Blocks(title="Kosmos-2", theme=gr.themes.Base()).queue() as demo:
|
| 21 |
+
gr.Markdown(("""
|
| 22 |
+
# Kosmos-2: Grounding Multimodal Large Language Models to the World
|
| 23 |
+
[[Paper]](https://arxiv.org/abs/2306.14824) [[Code]](https://github.com/microsoft/unilm/blob/master/kosmos-2)
|
| 24 |
+
"""))
|
| 25 |
+
with gr.Row():
|
| 26 |
+
with gr.Column():
|
| 27 |
+
image_input = gr.Image(type="pil", label="Test Image")
|
| 28 |
+
text_input = gr.Radio(["Brief", "Detailed"], label="Description Type", value="Brief")
|
| 29 |
+
do_sample = gr.Checkbox(label="Enable Sampling", info="(Please enable it before adjusting sampling parameters below)", value=False)
|
| 30 |
+
with gr.Accordion("Sampling parameters", open=False) as sampling_parameters:
|
| 31 |
+
sampling_topp = gr.Slider(minimum=0.1, maximum=1, step=0.01, value=0.9, label="Sampling: Top-P")
|
| 32 |
+
sampling_temperature = gr.Slider(minimum=0.1, maximum=1, step=0.01, value=0.7, label="Sampling: Temperature")
|
| 33 |
+
|
| 34 |
+
run_button = gr.Button(label="Run", visible=True)
|
| 35 |
+
|
| 36 |
+
with gr.Column():
|
| 37 |
+
image_output = gr.Image(type="pil")
|
| 38 |
+
text_output1 = gr.HighlightedText(
|
| 39 |
+
label="Generated Description",
|
| 40 |
+
combine_adjacent=False,
|
| 41 |
+
show_legend=True,
|
| 42 |
+
).style(color_map={"box": "red"})
|
| 43 |
+
|
| 44 |
+
with gr.Row():
|
| 45 |
+
with gr.Column():
|
| 46 |
+
gr.Examples(examples=[
|
| 47 |
+
["demo/images/two_dogs.jpg", "Detailed", False],
|
| 48 |
+
["demo/images/snowman.png", "Brief", False],
|
| 49 |
+
["demo/images/man_ball.png", "Detailed", False],
|
| 50 |
+
], inputs=[image_input, text_input, do_sample])
|
| 51 |
+
with gr.Column():
|
| 52 |
+
gr.Examples(examples=[
|
| 53 |
+
["demo/images/six_planes.png", "Brief", False],
|
| 54 |
+
["demo/images/quadrocopter.jpg", "Brief", False],
|
| 55 |
+
["demo/images/carnaby_street.jpg", "Brief", False],
|
| 56 |
+
], inputs=[image_input, text_input, do_sample])
|
| 57 |
+
gr.Markdown(term_of_use)
|
| 58 |
+
|
| 59 |
+
run_button.click(fn=generate_predictions,
|
| 60 |
+
inputs=[image_input, text_input, do_sample, sampling_topp, sampling_temperature],
|
| 61 |
+
outputs=[image_output, text_output1],
|
| 62 |
+
show_progress=True, queue=True)
|
| 63 |
+
|
| 64 |
+
demo.launch(share=True)
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
if __name__ == "__main__":
|
| 68 |
+
main()
|