tonyassi's picture
Update app.py
f43f5f2 verified
raw
history blame
No virus
2.17 kB
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):
# Predict decade from image
pred = decade(images=img)
# Write output text
res = """
# """ + pred[0]['label']
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: tony.assi.media@gmail.com">Email me</a> for business inquiries.
![](https://cdn.discordapp.com/attachments/1120417968032063538/1184251611388850257/all.png?ex=658b4b42&is=6578d642&hm=6b853c5b1e92d07701496f5fcb3106c6cef15c66a1a238ceedb214b4d9348245&)
""",
inputs=gr.Image(type="pil"),
outputs=gr.Markdown(),
theme = gr.themes.Base(primary_hue="teal",secondary_hue="teal",neutral_hue="slate"),
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()