EdZ543 commited on
Commit
d6eaf98
1 Parent(s): 43dde99

Add anime selection

Browse files

Former-commit-id: 8543a83f1cbed17a0956c6e1021a480a527af98c

.DS_Store ADDED
Binary file (6.15 kB). View file
 
app.py CHANGED
@@ -1,9 +1,66 @@
 
1
  import gradio as gr
 
 
 
 
 
2
 
 
3
 
4
- def greet(name):
5
- return "Hello " + name + "!!"
6
 
 
7
 
8
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
9
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
  import gradio as gr
3
+ import pandas as pd
4
+ import numpy as np
5
+ import requests
6
+ from urllib import parse
7
+ from dotenv import load_dotenv
8
 
9
+ load_dotenv()
10
 
11
+ anime_indexes = pd.read_csv("./data/anime_indexes.csv")
12
+ animes = anime_indexes["Anime"].values.tolist()
13
 
14
+ MAL_CLIENT_ID = os.getenv("MAL_CLIENT_ID")
15
 
16
+
17
+ def fetch_anime_image(anime):
18
+ query_url = f"https://api.myanimelist.net/v2/anime?q={parse.quote(anime)}&limit=1"
19
+ headers = {"X-MAL-CLIENT-ID": MAL_CLIENT_ID}
20
+ query_response = requests.get(query_url, headers=headers)
21
+ image_url = query_response.json()["data"][0]["node"]["main_picture"]["large"]
22
+ return image_url
23
+
24
+
25
+ def recommend(anime):
26
+ return None
27
+
28
+
29
+ css = """
30
+ #selection_column {align-items: center}
31
+ """
32
+
33
+ with gr.Blocks(css=css) as space:
34
+ gr.Markdown(
35
+ """
36
+ # Anime Collaborative Filtering Recommender
37
+ This is a Pytorch recommendation model that uses neural collaborative filtering.
38
+ Enter an anime, and it will suggest similar shows!
39
+ """
40
+ )
41
+
42
+ with gr.Box():
43
+ gr.Markdown("Enter an anime:")
44
+
45
+ with gr.Column(elem_id="selection_column"):
46
+ dropdown = gr.Dropdown(container=False, choices=animes)
47
+ selection_image = gr.Image(show_label=False, width=225, visible=False)
48
+
49
+ gallery = gr.Gallery(label="Recommendations")
50
+
51
+ def submit(anime):
52
+ if anime is None:
53
+ return {
54
+ selection_image: gr.update(visible=False),
55
+ gallery: gr.update(value=[]),
56
+ }
57
+
58
+ selection_image_url = fetch_anime_image(anime)
59
+
60
+ return {
61
+ selection_image: gr.update(visible=True, value=selection_image_url),
62
+ }
63
+
64
+ dropdown.change(fn=submit, inputs=dropdown, outputs=[selection_image, gallery])
65
+
66
+ space.launch()
data/anime_embeddings.csv.REMOVED.git-id ADDED
@@ -0,0 +1 @@
 
 
1
+ 99eecf79e2202579192c9d55c0e57797e5e6fc31
data/anime_indexes.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:48749adb822c3263d0908ada04a644f998d38766d7e5a8a470d3dff478ee316a
3
+ size 36209589
flagged/log.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ name,output,flag,username,timestamp
2
+ World,Hello World!!,,,2023-07-20 12:35:48.395137
3
+ World,Hello World!!,,,2023-07-20 12:35:52.353118