Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
from gradio_client import Client
|
4 |
+
|
5 |
+
MY_HF_TOKEN_KEY = os.environ["MY_HF_TOKEN_KEY"]
|
6 |
+
|
7 |
+
client = Client("Ghana-NLP/Khaya-image-caption-backend",hf_token=MY_HF_TOKEN_KEY)
|
8 |
+
|
9 |
+
def generate(filepath,language):
|
10 |
+
output = client.predict(filepath,language,api_name="/predict")
|
11 |
+
return output
|
12 |
+
|
13 |
+
with gr.Blocks() as demo:
|
14 |
+
title = gr.Markdown(
|
15 |
+
"""
|
16 |
+
# African Language Image Captioning
|
17 |
+
Based on the Khaya AI & Lesan APIs and the BLIP model"
|
18 |
+
""")
|
19 |
+
language_selector = gr.Dropdown(["Twi","Dagbani","Ewe","Ga","Gurene","Fante","Hausa", "Kikuyu", "Kimeru", "Luo","Shona","Swahili","Tigrinya","Yoruba"],value="Twi",label="Choose Language! (default is Twi)", info="Language:")
|
20 |
+
inputs = [gr.Image(type="pil"),language_selector)]
|
21 |
+
outputs = [gr.Textbox(label="English Caption"), gr.Textbox(label="African Language Caption"),
|
22 |
+
gr.Image(label="Output image with predicted instances", type="pil")]
|
23 |
+
examples = [["https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png"],
|
24 |
+
["https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/rotated_image.jpeg"]]
|
25 |
+
btn = gr.Button("Generate African Language Caption")
|
26 |
+
btn.click(generate, inputs=inputs, outputs=outputs)
|
27 |
+
|
28 |
+
if __name__ == "__main__":
|
29 |
+
demo.queue(max_size=20).launch()
|