Spaces:
Runtime error
Runtime error
Add image prediction
Browse files
app.py
CHANGED
|
@@ -18,6 +18,21 @@ MODELS = {
|
|
| 18 |
}
|
| 19 |
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
def query(payload, model_name):
|
| 22 |
data = json.dumps(payload)
|
| 23 |
# print("model url:", MODELS[model_name]["url"])
|
|
@@ -145,7 +160,15 @@ if st.button("Run"):
|
|
| 145 |
result = result[0]["generated_text"]
|
| 146 |
st.write(result.replace("\n", " \n"))
|
| 147 |
st.text("Translation")
|
|
|
|
| 148 |
if lang == "id":
|
| 149 |
-
st.write(
|
| 150 |
else:
|
| 151 |
st.write(translate(result, lang, "id").replace("\n", " \n"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
}
|
| 19 |
|
| 20 |
|
| 21 |
+
def get_image(text: str):
|
| 22 |
+
url = "https://wikisearch.uncool.ai/get_image/"
|
| 23 |
+
try:
|
| 24 |
+
payload = {
|
| 25 |
+
"text": text,
|
| 26 |
+
"image_width": 400
|
| 27 |
+
}
|
| 28 |
+
data = json.dumps(payload)
|
| 29 |
+
response = requests.request("POST", url, headers=headers, data=data)
|
| 30 |
+
print(response.content)
|
| 31 |
+
image = json.loads(response.content.decode("utf-8"))["url"]
|
| 32 |
+
except:
|
| 33 |
+
image = ""
|
| 34 |
+
return image
|
| 35 |
+
|
| 36 |
def query(payload, model_name):
|
| 37 |
data = json.dumps(payload)
|
| 38 |
# print("model url:", MODELS[model_name]["url"])
|
|
|
|
| 160 |
result = result[0]["generated_text"]
|
| 161 |
st.write(result.replace("\n", " \n"))
|
| 162 |
st.text("Translation")
|
| 163 |
+
translation = translate(result, "en", "id")
|
| 164 |
if lang == "id":
|
| 165 |
+
st.write(translation.replace("\n", " \n"))
|
| 166 |
else:
|
| 167 |
st.write(translate(result, lang, "id").replace("\n", " \n"))
|
| 168 |
+
|
| 169 |
+
image_cat = "https://media.giphy.com/media/vFKqnCdLPNOKc/giphy.gif"
|
| 170 |
+
image = get_image(translation)
|
| 171 |
+
if image is not "":
|
| 172 |
+
st.image(image, width=400)
|
| 173 |
+
else:
|
| 174 |
+
st.image(image_cat, width=400)
|