Spaces:
Running
Running
bilgeyucel
commited on
Commit
•
cfadd82
1
Parent(s):
6bf02ba
Update the ui
Browse files
app.py
CHANGED
@@ -7,9 +7,11 @@ from haystack import Pipeline
|
|
7 |
|
8 |
description = """
|
9 |
# Captionate ✨ 📸
|
10 |
-
## Create Instagram captions for your
|
11 |
|
12 |
-
|
|
|
|
|
13 |
"""
|
14 |
|
15 |
image_to_text = TransformersImageToText(
|
@@ -19,9 +21,9 @@ image_to_text = TransformersImageToText(
|
|
19 |
|
20 |
prompt_template = PromptTemplate(prompt="""
|
21 |
You will receive a descriptive text of a photo.
|
22 |
-
Try to come up with a nice Instagram caption that has a phrase rhyming with the text.
|
23 |
|
24 |
-
Descriptive text:{documents};
|
25 |
Caption:
|
26 |
""")
|
27 |
|
@@ -33,15 +35,15 @@ def generate_caption(image_file_paths, model_name):
|
|
33 |
captioning_pipeline.add_node(component=image_to_text, name="image_to_text", inputs=["File"])
|
34 |
captioning_pipeline.add_node(component=prompt_node, name="prompt_node", inputs=["image_to_text"])
|
35 |
caption = captioning_pipeline.run(file_paths=[image_file_paths])
|
36 |
-
print(caption)
|
37 |
return caption["results"][0]
|
38 |
|
39 |
-
with gr.Blocks(theme="
|
40 |
gr.Markdown(value=description)
|
41 |
-
|
42 |
-
|
|
|
43 |
submit_btn = gr.Button("✨ Captionate ✨")
|
44 |
-
caption = gr.Textbox(label="Caption")
|
45 |
submit_btn.click(fn=generate_caption, inputs=[image, model_name], outputs=[caption])
|
46 |
|
47 |
if __name__ == "__main__":
|
|
|
7 |
|
8 |
description = """
|
9 |
# Captionate ✨ 📸
|
10 |
+
## Create Instagram captions for your pics!
|
11 |
|
12 |
+
|
13 |
+
|
14 |
+
Built by [Bilge Yucel](https://twitter.com/bilgeycl) using [Haystack](https://github.com/deepset-ai/haystack) 💙
|
15 |
"""
|
16 |
|
17 |
image_to_text = TransformersImageToText(
|
|
|
21 |
|
22 |
prompt_template = PromptTemplate(prompt="""
|
23 |
You will receive a descriptive text of a photo.
|
24 |
+
Try to come up with a nice Instagram caption that has a phrase rhyming with the text. Include emojis to the caption.
|
25 |
|
26 |
+
Descriptive text: {documents};
|
27 |
Caption:
|
28 |
""")
|
29 |
|
|
|
35 |
captioning_pipeline.add_node(component=image_to_text, name="image_to_text", inputs=["File"])
|
36 |
captioning_pipeline.add_node(component=prompt_node, name="prompt_node", inputs=["image_to_text"])
|
37 |
caption = captioning_pipeline.run(file_paths=[image_file_paths])
|
|
|
38 |
return caption["results"][0]
|
39 |
|
40 |
+
with gr.Blocks(theme="monochrome") as demo:
|
41 |
gr.Markdown(value=description)
|
42 |
+
with gr.Row():
|
43 |
+
image = gr.Image(type="filepath")
|
44 |
+
model_name = gr.Dropdown(["tiiuae/falcon-7b-instruct", "tiiuae/falcon-7b", "EleutherAI/gpt-neox-20b", "HuggingFaceH4/starchat-beta", "OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5", "bigscience/bloom"], value="tiiuae/falcon-7b-instruct", label="Choose your model!")
|
45 |
submit_btn = gr.Button("✨ Captionate ✨")
|
46 |
+
caption = gr.Textbox(label="Caption", show_copy_button=True)
|
47 |
submit_btn.click(fn=generate_caption, inputs=[image, model_name], outputs=[caption])
|
48 |
|
49 |
if __name__ == "__main__":
|