repl.it
@lachlanjc/

NOT HOTDOG

Python

No description

fork
loading
Files
  • main.py
  • file_name
  • file_name.png
  • font.ttf
  • hotdog.png
  • Packager files
  • requirements.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
API_KEY = os.getenv("API_KEY")

print (API_KEY)

from clarifai.rest import ClarifaiApp
from clarifai.rest import Image

app = ClarifaiApp(api_key=API_KEY)

model = app.models.get("food-items-v1.0")

url = "https://i.amz.mshcdn.com/vZ_SBZAS-HjH0iWqay5kJYHlvSY=/1200x630/2017%2F07%2F12%2Faf%2F5ee9a826a4f5430190681a4f6eb6fbed.93444.jpg"

image = Image(url=url)

result = model.predict([image])

hotdog = False

for concept in result["outputs"][0]["data"]["concepts"]:
	if concept["name"] == "hotdog" or concept["name"] == "hot dog":
		hotdog = True
		break

if hotdog:
	print ("Hotdog")
else:
	print ("Not hotdog")

from PIL import Image, ImageDraw, ImageFont

import requests
from io import BytesIO

response = requests.get(url)
base = Image.open(BytesIO(response.content)).convert('RGBA')

size = width, height = base.size
if size[0] < 1200:
	base = base.resize((1200,int(size[1]*1200/size[0])))
size = width, height = base.size

draw = ImageDraw.Draw(base,"RGBA")

font = ImageFont.truetype("font.ttf",100)

text = "Hotdog" if hotdog else "Not hotdog"
x = 275 if hotdog else 50
y = 10

w, h = font.getsize(text)
draw.rectangle((x, y, x + w, y + h), fill="green" if hotdog else "red")

if hotdog:
	draw.text((x,y),"Hotdog",(0,0,0,255), font=font)
else:
	draw.text((x,y),"Not hotdog",(0,0,0,255), font=font)
base.save("hotdog.png")
?