Spaces:
Runtime error
Runtime error
from turtle import ht | |
import requests | |
import gradio as gr | |
def make_request(img_url, min_score): | |
headers = { | |
'accept': 'application/json', | |
'public-key': 'xxx', | |
} | |
params = { | |
'url': img_url, | |
'min_score': min_score, | |
} | |
response = requests.get('https://api-similarity-zx53qegsda-as.a.run.app/v1/similarity/', params=params, headers=headers) | |
result = response.json() | |
return result | |
def show_result(image_url, min_score=0.7): | |
result = make_request(image_url, min_score) | |
html = f'<img src="{image_url}" width="300">Original Image<br/><br/>' | |
if len(result['result']) == 0: | |
html += '<h3>No Similar Photo Found</h3>' | |
else: | |
html += f'<h4>{len(result["result"])} Photos Found</h4><br><hr/><br/>' | |
html += '<table><tr>' | |
for i, raw in enumerate(result['result']): | |
detail = raw["detail"] | |
html += f''' | |
<td style="vertical-align:top"> | |
<img src="{raw["url"]}" width="300"/> | |
<p>{raw["similarity"] * 100}%</p> | |
<p> Title: {detail["title"]} </p> | |
<p> User : {detail["user"]["name"]} </p> | |
<br/> | |
</td> | |
''' | |
if i > 0 and i%2 == 1: | |
html += '</tr><tr>' | |
html += "</table>" | |
return (html) | |
demo = gr.Interface(fn=show_result, inputs=["text","text"], outputs=["html"]) | |
demo.launch(debug=False) |