Spaces:
Running
Running
bilgeyucel
commited on
Commit
•
85f65db
1
Parent(s):
8606aa2
Add model options
Browse files
app.py
CHANGED
@@ -26,13 +26,12 @@ Caption:
|
|
26 |
""")
|
27 |
|
28 |
hf_api_key = os.environ["HF_API_KEY"]
|
29 |
-
prompt_node = PromptNode(model_name_or_path="tiiuae/falcon-7b-instruct", api_key=hf_api_key, default_prompt_template=prompt_template, model_kwargs={"trust_remote_code":True})
|
30 |
-
|
31 |
captioning_pipeline = Pipeline()
|
32 |
-
captioning_pipeline.add_node(component=image_to_text, name="image_to_text", inputs=["File"])
|
33 |
-
captioning_pipeline.add_node(component=prompt_node, name="prompt_node", inputs=["image_to_text"])
|
34 |
|
35 |
-
def generate_caption(image_file_paths):
|
|
|
|
|
|
|
36 |
caption = captioning_pipeline.run(file_paths=[image_file_paths])
|
37 |
print(caption)
|
38 |
return caption["results"][0]
|
@@ -40,10 +39,10 @@ def generate_caption(image_file_paths):
|
|
40 |
with gr.Blocks(theme="soft") as demo:
|
41 |
gr.Markdown(value=description)
|
42 |
image = gr.Image(type="filepath")
|
43 |
-
|
44 |
submit_btn = gr.Button("✨ Captionate ✨")
|
45 |
caption = gr.Textbox(label="Caption")
|
46 |
-
submit_btn.click(fn=generate_caption, inputs=[image], outputs=[caption])
|
47 |
|
48 |
if __name__ == "__main__":
|
49 |
demo.launch()
|
|
|
26 |
""")
|
27 |
|
28 |
hf_api_key = os.environ["HF_API_KEY"]
|
|
|
|
|
29 |
captioning_pipeline = Pipeline()
|
|
|
|
|
30 |
|
31 |
+
def generate_caption(image_file_paths, model_name):
|
32 |
+
prompt_node = PromptNode(model_name_or_path=model_name, api_key=hf_api_key, default_prompt_template=prompt_template, model_kwargs={"trust_remote_code":True})
|
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]
|
|
|
39 |
with gr.Blocks(theme="soft") as demo:
|
40 |
gr.Markdown(value=description)
|
41 |
image = gr.Image(type="filepath")
|
42 |
+
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", "timdettmers/guanaco-33b-merged", "bigscience/bloom"], value="tiiuae/falcon-7b-instruct", label="Choose your model!")
|
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__":
|
48 |
demo.launch()
|