Spaces:
Running
Running
File size: 2,165 Bytes
3bef070 f0ea29c c2532a6 794a4e3 3bef070 f0ea29c 3bef070 c2532a6 4314aed c2532a6 4314aed f0ea29c 0e3b73d c2532a6 0f81ffc f0ea29c 738ad39 02a2f02 738ad39 bb7da1a c9dcb6a 738ad39 77cd777 d706dfe 0e3b73d 3bef070 |
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 60 61 |
import gradio as gr
from transformers import pipeline
import requests
import json
import os
decade = pipeline(model="tonyassi/fashion-clothing-decade")
def mistral(decade):
url = os.environ.get('MISTRAL_URL')
# Define the prompt
prompt = "write a fun,short description of the " + decade + " in 1-2 sentences"
# Mistral API call
payload = json.dumps({
"key": os.environ.get('MISTRAL_KEY'),
"messages": [
{
"role": "user",
"content": prompt
},
],
"max_tokens": 1000
})
headers = {
'Content-Type': 'application/json'
}
# API response
response = requests.request("POST", url, headers=headers, data=payload)
response = json.loads(response.text)
return response['message']
def greet(img):
pred = decade(images=img)
res = """
# """ + pred[0]['label'] + """
""" + mistral(pred[0]['label'])
#res += pred[1]['label'] + ':' + str(pred[1]['score']) + '\n'
#res += pred[2]['label'] + ':' + str(pred[2]['score'])
return res
iface = gr.Interface(fn=greet,
title='Which Decade Are You From?',
description="""
by [Tony Assi](https://www.tonyassi.com/)
This space uses the [fashion-clothing-decade](https://huggingface.co/tonyassi/fashion-clothing-decade) image classification model. Please ❤️ this Space.
I build custom AI apps for companies. <a href="mailto: [email protected]">Email me</a> for business inquiries.

""",
inputs=gr.Image(type="pil"),
outputs=gr.Markdown(),
examples=[['./examples/1910s.jpg'],['./examples/1920s.jpg'],['./examples/1930s.jpg'],['./examples/1940s.jpg'],['./examples/1950s.jpg'],['./examples/1960s.jpg'],['./examples/1970s.jpg'],['./examples/1980s.jpg'],['./examples/1990s.jpg'],['./examples/2000s.jpg'],]
)
iface.launch() |