File size: 2,171 Bytes
3bef070
f0ea29c
c2532a6
 
794a4e3
3bef070
f0ea29c
3bef070
c2532a6
4314aed
 
 
c2532a6
4314aed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f0ea29c
422946d
f0ea29c
422946d
 
0e3b73d
f43f5f2
422946d
f0ea29c
 
738ad39
 
 
 
 
02a2f02
738ad39
 
bb7da1a
 
c9dcb6a
738ad39
77cd777
b622c35
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
62
63
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: [email protected]">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()