Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
def get_openai_key():
|
5 |
+
return os.getenv("OPENAI_API_KEY","")
|
6 |
+
|
7 |
+
openai_api_key = gr.inputs.Textbox(value=get_openai_key(),label="OpenAI API Key",type="password")
|
8 |
+
image_input = gr.inputs.Image(type='filepath', label="Input Image")
|
9 |
+
|
10 |
+
title_with_logo = \
|
11 |
+
f'Understanding Image with Text'
|
12 |
+
|
13 |
+
|
14 |
+
interface = gr.Interface(
|
15 |
+
inputs=[openai_api_key,
|
16 |
+
image_input,
|
17 |
+
gr.CheckboxGroup(
|
18 |
+
label="Options",
|
19 |
+
choices=["Image Generation", "Semantic Segment"],
|
20 |
+
),
|
21 |
+
],
|
22 |
+
outputs=gr.outputs.HTML(),
|
23 |
+
title=title_with_logo,
|
24 |
+
description=extra_title +"""
|
25 |
+
Image.txt. This code support image to text transformation. Then the generated text can do retrieval, question answering et al to conduct zero-shot.
|
26 |
+
\n Github: https://github.com/showlab/Image2Paragraph
|
27 |
+
\n Twitter: https://twitter.com/awinyimgprocess/status/1646225454599372800?s=46&t=HvOe9T2n35iFuCHP5aIHpQ
|
28 |
+
\n For online demo, we use smallest model to speed up. For better result, look for github for using large models.
|
29 |
+
\n Ttext2image model is controlnet, which used canny edge as reference.
|
30 |
+
\n To speed up, we generate image with small size 384, run the code local for high-quality sample.
|
31 |
+
"""
|
32 |
+
)
|
33 |
+
|
34 |
+
# Launch the interface
|
35 |
+
interface.launch()
|
36 |
+
|