Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
134 lines (114 sloc) 4.5 KB
<!DOCTYPE html>
<html>
<head>
<link href='https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons' rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify/dist/vuetify.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify/dist/vuetify.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<div id="app">
<v-app>
<v-content>
<v-container>
<v-layout align-center justify-center>
<v-flex xs12 sm6 md3>
<v-text-field
label="Image ID"
placeholder=""
v-model="image.id"
@input="onImageIDChange">
></v-text-field>
</v-flex>
<v-btn color="blue" dark large @click="loadRandomImage" >
Another &nbsp; <v-icon>refresh</v-icon>
</v-btn>
</v-layout>
<v-layout row wrap>
<v-flex xs12 >
<v-card flat tile class="d-flex">
<v-img :src="image.url" height="400px" contain>
</v-img>
</v-card>
</v-flex>
</v-layout>
<v-layout row wrap>
<v-flex xs12 >
<v-data-table
:headers="headers"
:items="image_analysis"
class="elevation-1"
:total-items="image_analysis.length"
hide-actions
>
<template slot="items" slot-scope="props">
<td>{{ props.item.Name }}</td>
<td>{{ props.item.Confidence }}</td>
</template>
</v-data-table>
</v-flex>
</v-layout>
</v-container>
</v-content>
</v-app>
</div>
<script>
new Vue({
el: '#app',
data: {
image_analysis:[],
image: {id:"", url: ""},
headers: [
{ text: 'Name' },
{ text: 'Confidence' }
],
},
created(){
this.loadRandomImage();
} ,
methods:{
async loadRandomImage()
{
try{
axios.defaults.headers.common['x-api-key'] = "DEMO-API-KEY" // Replace this with your API Key
let response = await axios.get('https://api.thecatapi.com/v1/images/search', { params: { limit:1, size:"full" , mime_types:"jpg,png"} } ) // Ask for 1 Image, at full resolution
this.image = response.data[0] // the response is an Array, so just use the first item as the Image
console.log("-- Image from TheCatAPI.com")
console.log("id:", this.image.id)
console.log("url:", this.image.url)
this.loadImageAnaylsis(this.image.id)
}catch(err){
console.log(err)
}
},
async onImageIDChange(user_input)
{
this.loadImage(user_input)
},
async loadImage(image_id){
let response = await axios.get('https://api.thecatapi.com/v1/images/'+image_id ) // Ask for 1 Image, at full resolution
this.image = response.data // the response is an Object not an Array as it will only return one Image
console.log("-- Image from TheCatAPI.com")
console.log("id:", this.image.id)
console.log("url:", this.image.url)
this.loadImageAnaylsis(this.image.id)
},
async loadImageAnaylsis(image_id)
{
let response = await axios.get('https://api.thecatapi.com/v1/images/'+image_id +"/analysis") // Ask for 1 Image, at full resolution
try{
this.image_analysis = response.data[0].labels
console.table(response.data[0].labels)
}catch(err)
{
this.image_analysis = [{Name:"No analysis available",Confidence:"100"}];
console.table('No analysis available.')
}
}
}
})
</script>
</body>
</html>
You can’t perform that action at this time.