Spaces:
Build error
Build error
style: run linter
Browse files- image2text.py +12 -10
image2text.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import requests
|
| 3 |
-
import numpy as np
|
| 4 |
import jax
|
| 5 |
import jax.numpy as jnp
|
| 6 |
-
|
| 7 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
from utils import load_model
|
| 10 |
|
|
@@ -25,19 +25,23 @@ def app(model_name):
|
|
| 25 |
query2 = st.text_input("or a URL to an image...")
|
| 26 |
|
| 27 |
captions = st.text_input(
|
| 28 |
-
"Enter candidate captions in comma-separated form.",
|
| 29 |
-
value="๊ท์ฌ์ด ๊ณ ์์ด,๋ฉ์๋ ๊ฐ์์ง,ํธ๋์คํฌ๋จธ"
|
| 30 |
)
|
| 31 |
|
| 32 |
if st.button("์ง๋ฌธ (Query)"):
|
| 33 |
if not any([query1, query2]):
|
| 34 |
st.error("Please upload an image or paste an image URL.")
|
| 35 |
else:
|
| 36 |
-
image_data =
|
|
|
|
|
|
|
| 37 |
image = Image.open(image_data)
|
| 38 |
st.image(image)
|
| 39 |
captions = captions.split(",")
|
| 40 |
-
inputs = processor(
|
|
|
|
|
|
|
| 41 |
inputs["pixel_values"] = jnp.transpose(
|
| 42 |
inputs["pixel_values"], axes=[0, 2, 3, 1]
|
| 43 |
)
|
|
@@ -48,5 +52,3 @@ def app(model_name):
|
|
| 48 |
st.bar_chart(df)
|
| 49 |
# for idx, prob in sorted(enumerate(*probs), key=lambda x: x[1], reverse=True):
|
| 50 |
# st.text(f"Score: `{prob}`, {captions[idx]}")
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import jax
|
| 2 |
import jax.numpy as jnp
|
| 3 |
+
import numpy as np
|
| 4 |
import pandas as pd
|
| 5 |
+
import requests
|
| 6 |
+
import streamlit as st
|
| 7 |
+
from PIL import Image
|
| 8 |
|
| 9 |
from utils import load_model
|
| 10 |
|
|
|
|
| 25 |
query2 = st.text_input("or a URL to an image...")
|
| 26 |
|
| 27 |
captions = st.text_input(
|
| 28 |
+
"Enter candidate captions in comma-separated form.",
|
| 29 |
+
value="๊ท์ฌ์ด ๊ณ ์์ด,๋ฉ์๋ ๊ฐ์์ง,ํธ๋์คํฌ๋จธ",
|
| 30 |
)
|
| 31 |
|
| 32 |
if st.button("์ง๋ฌธ (Query)"):
|
| 33 |
if not any([query1, query2]):
|
| 34 |
st.error("Please upload an image or paste an image URL.")
|
| 35 |
else:
|
| 36 |
+
image_data = (
|
| 37 |
+
query1 if query1 is not None else requests.get(query2, stream=True).raw
|
| 38 |
+
)
|
| 39 |
image = Image.open(image_data)
|
| 40 |
st.image(image)
|
| 41 |
captions = captions.split(",")
|
| 42 |
+
inputs = processor(
|
| 43 |
+
text=captions, images=image, return_tensors="jax", padding=True
|
| 44 |
+
)
|
| 45 |
inputs["pixel_values"] = jnp.transpose(
|
| 46 |
inputs["pixel_values"], axes=[0, 2, 3, 1]
|
| 47 |
)
|
|
|
|
| 52 |
st.bar_chart(df)
|
| 53 |
# for idx, prob in sorted(enumerate(*probs), key=lambda x: x[1], reverse=True):
|
| 54 |
# st.text(f"Score: `{prob}`, {captions[idx]}")
|
|
|
|
|
|