Bytte commited on
Commit
423ef2f
·
1 Parent(s): d9f1e23

Upload 6 files

Browse files
Files changed (6) hide show
  1. Dockerfile +21 -0
  2. __init__.py +0 -0
  3. main.py +28 -0
  4. mini_data.csv +55 -0
  5. recommend.py +60 -0
  6. requirements.txt +10 -0
Dockerfile ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --upgrade pip
8
+
9
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
10
+
11
+ COPY ./__init__.py /code/__init__.py
12
+
13
+ COPY ./.env /code/.env
14
+
15
+ COPY ./mini_data.csv /code/mini_data.csv
16
+
17
+ COPY ./recommend.py /code/recommend.py
18
+
19
+ COPY ./main.py /code/main.py
20
+
21
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
__init__.py ADDED
File without changes
main.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from recommend import vector_search
3
+ from pydantic import BaseModel
4
+ import requests
5
+ import pandas as pd
6
+
7
+ df = pd.read_csv('mini_data.csv')
8
+
9
+
10
+ class validation(BaseModel):
11
+ title: str
12
+
13
+
14
+ app = FastAPI()
15
+
16
+
17
+ @app.post('/recommend')
18
+ def get_recommendations(items: validation):
19
+ anime = df[df['title'] == items.title]
20
+
21
+ if len(anime) == 0:
22
+ return None
23
+
24
+ desc = anime['description']
25
+
26
+ completion = vector_search(desc)
27
+
28
+ return completion
mini_data.csv ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ,id,url,trailer,title,number_of_episodes,status,is_airing,duration_per_episode,rating,score,rank,popularity,description,,genres,themes,streaming_sites
2
+ 0,1,https://myanimelist.net/anime/1/Cowboy_Bebop,https://www.youtube.com/watch?v=gY5nDXOtv_o,Cowboy Bebop,26,Finished Airing,False,24 min per ep,R - 17+ (violence & profanity),8.75,44,43,"Crime is timeless. By the year 2071, humanity has expanded across the galaxy, filling the surface of other planets with settlements like those on Earth. These new societies are plagued by murder, drug use, and theft, and intergalactic outlaws are hunted by a growing number of tough bounty hunters.
3
+
4
+ Spike Spiegel and Jet Black pursue criminals throughout space to make a humble living. Beneath his goofy and aloof demeanor, Spike is haunted by the weight of his violent past. Meanwhile, Jet manages his own troubled memories while taking care of Spike and the Bebop, their ship. The duo is joined by the beautiful con artist Faye Valentine, odd child Edward Wong Hau Pepelu Tivrusky IV, and Ein, a bioengineered Welsh Corgi.
5
+
6
+ While developing bonds and working to catch a colorful cast of criminals, the Bebop crew's lives are disrupted by a menace from Spike's past. As a rival's maniacal plot continues to unravel, Spike must choose between life with his newfound family or revenge for his old wounds.
7
+
8
+ [Written by MAL Rewrite]",1998.0,"[{'mal_id': 1, 'type': 'anime', 'name': 'Action', 'url': 'https://myanimelist.net/anime/genre/1/Action'}, {'mal_id': 46, 'type': 'anime', 'name': 'Award Winning', 'url': 'https://myanimelist.net/anime/genre/46/Award_Winning'}, {'mal_id': 24, 'type': 'anime', 'name': 'Sci-Fi', 'url': 'https://myanimelist.net/anime/genre/24/Sci-Fi'}]","[{'mal_id': 50, 'type': 'anime', 'name': 'Adult Cast', 'url': 'https://myanimelist.net/anime/genre/50/Adult_Cast'}, {'mal_id': 29, 'type': 'anime', 'name': 'Space', 'url': 'https://myanimelist.net/anime/genre/29/Space'}]","[{'name': 'Crunchyroll', 'url': 'http://www.crunchyroll.com/series-271225'}, {'name': 'Funimation', 'url': 'https://www.funimation.com/shows/cowboy-bebop'}, {'name': 'Netflix', 'url': 'https://www.netflix.com/title/80001305'}, {'name': 'Tubi TV', 'url': 'https://tubitv.com/series/2052/cowboy-bebop-subtitled'}]"
9
+ 1,5,https://myanimelist.net/anime/5/Cowboy_Bebop__Tengoku_no_Tobira,,Cowboy Bebop: Tengoku no Tobira,1,Finished Airing,False,1 hr 55 min,R - 17+ (violence & profanity),8.38,193,612,"Another day, another bounty—such is the life of the often unlucky crew of the Bebop. However, this routine is interrupted when Faye, who is chasing a fairly worthless target on Mars, witnesses an oil tanker suddenly explode, causing mass hysteria. As casualties mount due to a strange disease spreading through the smoke from the blast, a whopping three hundred million woolong price is placed on the head of the supposed perpetrator.
10
+
11
+ With lives at stake and a solution to their money problems in sight, the Bebop crew springs into action. Spike, Jet, Faye, and Edward, followed closely by Ein, split up to pursue different leads across Alba City. Through their individual investigations, they discover a cover-up scheme involving a pharmaceutical company, revealing a plot that reaches much further than the ragtag team of bounty hunters could have realized.
12
+
13
+ [Written by MAL Rewrite]",,"[{'mal_id': 1, 'type': 'anime', 'name': 'Action', 'url': 'https://myanimelist.net/anime/genre/1/Action'}, {'mal_id': 24, 'type': 'anime', 'name': 'Sci-Fi', 'url': 'https://myanimelist.net/anime/genre/24/Sci-Fi'}]","[{'mal_id': 50, 'type': 'anime', 'name': 'Adult Cast', 'url': 'https://myanimelist.net/anime/genre/50/Adult_Cast'}, {'mal_id': 29, 'type': 'anime', 'name': 'Space', 'url': 'https://myanimelist.net/anime/genre/29/Space'}]","[{'name': 'Netflix', 'url': 'https://www.netflix.com/'}]"
14
+ 2,6,https://myanimelist.net/anime/6/Trigun,https://www.youtube.com/watch?v=bJVyIXeUznY,Trigun,26,Finished Airing,False,24 min per ep,PG-13 - Teens 13 or older,8.22,333,248,"Vash the Stampede is the man with a $$60,000,000,000 bounty on his head. The reason: he's a merciless villain who lays waste to all those that oppose him and flattens entire cities for fun, garnering him the title ""The Humanoid Typhoon."" He leaves a trail of death and destruction wherever he goes, and anyone can count themselves dead if they so much as make eye contact—or so the rumors say. In actuality, Vash is a huge softie who claims to have never taken a life and avoids violence at all costs.
15
+
16
+ With his crazy doughnut obsession and buffoonish attitude in tow, Vash traverses the wasteland of the planet Gunsmoke, all the while followed by two insurance agents, Meryl Stryfe and Milly Thompson, who attempt to minimize his impact on the public. But soon, their misadventures evolve into life-or-death situations as a group of legendary assassins are summoned to bring about suffering to the trio. Vash's agonizing past will be unraveled and his morality and principles pushed to the breaking point.
17
+
18
+ [Written by MAL Rewrite]",1998.0,"[{'mal_id': 1, 'type': 'anime', 'name': 'Action', 'url': 'https://myanimelist.net/anime/genre/1/Action'}, {'mal_id': 2, 'type': 'anime', 'name': 'Adventure', 'url': 'https://myanimelist.net/anime/genre/2/Adventure'}, {'mal_id': 24, 'type': 'anime', 'name': 'Sci-Fi', 'url': 'https://myanimelist.net/anime/genre/24/Sci-Fi'}]","[{'mal_id': 50, 'type': 'anime', 'name': 'Adult Cast', 'url': 'https://myanimelist.net/anime/genre/50/Adult_Cast'}]","[{'name': 'Crunchyroll', 'url': 'http://www.crunchyroll.com/series-275669'}, {'name': 'Funimation', 'url': 'https://www.funimation.com/shows/trigun'}, {'name': 'Netflix', 'url': 'https://www.netflix.com/'}]"
19
+ 3,7,https://myanimelist.net/anime/7/Witch_Hunter_Robin,https://www.youtube.com/watch?v=7UkaILjPk8M,Witch Hunter Robin,26,Finished Airing,False,25 min per ep,PG-13 - Teens 13 or older,7.24,2943,1828,"Robin Sena is a powerful craft user drafted into the STNJ—a group of specialized hunters that fight deadly beings known as Witches. Though her fire power is great, she's got a lot to learn about her powers and working with her cool and aloof partner, Amon. But the truth about the Witches and herself will leave Robin on an entirely new path that she never expected!
20
+
21
+ (Source: Funimation)",2002.0,"[{'mal_id': 1, 'type': 'anime', 'name': 'Action', 'url': 'https://myanimelist.net/anime/genre/1/Action'}, {'mal_id': 8, 'type': 'anime', 'name': 'Drama', 'url': 'https://myanimelist.net/anime/genre/8/Drama'}, {'mal_id': 7, 'type': 'anime', 'name': 'Mystery', 'url': 'https://myanimelist.net/anime/genre/7/Mystery'}, {'mal_id': 37, 'type': 'anime', 'name': 'Supernatural', 'url': 'https://myanimelist.net/anime/genre/37/Supernatural'}]","[{'mal_id': 39, 'type': 'anime', 'name': 'Detective', 'url': 'https://myanimelist.net/anime/genre/39/Detective'}]","[{'name': 'Crunchyroll', 'url': 'http://www.crunchyroll.com/series-283299'}, {'name': 'Funimation', 'url': 'https://www.funimation.com/shows/witch-hunter-robin'}]"
22
+ 4,8,https://myanimelist.net/anime/8/Bouken_Ou_Beet,,Bouken Ou Beet,52,Finished Airing,False,23 min per ep,PG - Children,6.93,4440,5250,"It is the dark century and the people are suffering under the rule of the devil, Vandel, who is able to manipulate monsters. The Vandel Busters are a group of people who hunt these devils, and among them, the Zenon Squad is known to be the strongest busters on the continent. A young boy, Beet, dreams of joining the Zenon Squad. However, one day, as a result of Beet's fault, the Zenon squad was defeated by the devil, Beltose. The five dying busters sacrificed their life power into their five weapons, Saiga. After giving their weapons to Beet, they passed away. Years have passed since then and the young Vandel Buster, Beet, begins his adventure to carry out the Zenon Squad's will to put an end to the dark century.",2004.0,"[{'mal_id': 2, 'type': 'anime', 'name': 'Adventure', 'url': 'https://myanimelist.net/anime/genre/2/Adventure'}, {'mal_id': 10, 'type': 'anime', 'name': 'Fantasy', 'url': 'https://myanimelist.net/anime/genre/10/Fantasy'}, {'mal_id': 37, 'type': 'anime', 'name': 'Supernatural', 'url': 'https://myanimelist.net/anime/genre/37/Supernatural'}]",[],[]
23
+ 5,15,https://myanimelist.net/anime/15/Eyeshield_21,,Eyeshield 21,145,Finished Airing,False,23 min per ep,PG-13 - Teens 13 or older,7.91,741,1279,"Shy, reserved, and small-statured, Deimon High School student Sena Kobayakawa is the perfect target for bullies. However, as a result of running errands throughout his life, Sena has become agile and developed a skill for avoiding crowds of people. After the cunning Youichi Hiruma—captain of the Deimon Devil Bats football team—witnesses Sena's rapid legs in motion, he coerces the timid boy into joining his squad.
24
+
25
+ As Hiruma wants to conceal Sena's identity from other clubs, Sena is forced to hide under the visored helmet of ""Eyeshield 21,"" a mysterious running back wearing the number 21 jersey. The legendary Eyeshield 21 can supposedly run at the speed of light and has achieved remarkable feats in the United States during his time at the Notre Dame College.
26
+
27
+ Accustomed to avoiding his problems in the past, Sena's specialty might just help him become the new secret weapon of the Deimon Devil Bats. As he interacts with his teammates, Sena gradually gains more self-confidence and forges valuable bonds along the way.
28
+
29
+ [Written by MAL Rewrite]",2005.0,"[{'mal_id': 30, 'type': 'anime', 'name': 'Sports', 'url': 'https://myanimelist.net/anime/genre/30/Sports'}]","[{'mal_id': 77, 'type': 'anime', 'name': 'Team Sports', 'url': 'https://myanimelist.net/anime/genre/77/Team_Sports'}]","[{'name': 'Crunchyroll', 'url': 'http://www.crunchyroll.com/series-46844'}]"
30
+ 6,16,https://myanimelist.net/anime/16/Hachimitsu_to_Clover,https://www.youtube.com/watch?v=6TN4a0kZuXg,Hachimitsu to Clover,24,Finished Airing,False,23 min per ep,PG-13 - Teens 13 or older,8.0,616,881,"Yuuta Takemoto, a sophomore at an arts college, shares a cheap apartment with two seniors—the eccentric Shinobu Morita, who keeps failing to graduate due to his absenteeism, and the sensible Takumi Mayama, who acts as a proper senior to Takemoto, often looking out for him.
31
+
32
+ Takemoto had not given much thought to his future until one fine spring day, when he meets the endearing Hagumi Hanamoto and falls in love at first sight. Incredibly gifted in the arts, Hagumi enrolls in Takemoto's university and soon befriends the popular pottery student Ayumi Yamada. Ayumi is already well acquainted with the three flatmates and secretly harbors deep feelings for one of them.
33
+
34
+ Hachimitsu to Clover is a heartwarming tale of youth, love, soul-searching, and self-discovery, intricately woven through the complex relationships between five dear friends.
35
+
36
+ [Written by MAL Rewrite]",2005.0,"[{'mal_id': 4, 'type': 'anime', 'name': 'Comedy', 'url': 'https://myanimelist.net/anime/genre/4/Comedy'}, {'mal_id': 8, 'type': 'anime', 'name': 'Drama', 'url': 'https://myanimelist.net/anime/genre/8/Drama'}, {'mal_id': 22, 'type': 'anime', 'name': 'Romance', 'url': 'https://myanimelist.net/anime/genre/22/Romance'}]","[{'mal_id': 50, 'type': 'anime', 'name': 'Adult Cast', 'url': 'https://myanimelist.net/anime/genre/50/Adult_Cast'}, {'mal_id': 64, 'type': 'anime', 'name': 'Love Polygon', 'url': 'https://myanimelist.net/anime/genre/64/Love_Polygon'}, {'mal_id': 80, 'type': 'anime', 'name': 'Visual Arts', 'url': 'https://myanimelist.net/anime/genre/80/Visual_Arts'}]","[{'name': 'Crunchyroll', 'url': 'http://www.crunchyroll.com/series-277968'}]"
37
+ 7,17,https://myanimelist.net/anime/17/Hungry_Heart__Wild_Striker,,Hungry Heart: Wild Striker,52,Finished Airing,False,23 min per ep,PG-13 - Teens 13 or older,7.55,1635,4327,"As the younger brother of Japanese soccer star Seisuke Kanou, Kyousuke was always expected to grow as a soccer player at the same pace his brother did—an expectation that proved too difficult to meet. Having fallen behind, he now lives in the shadow of his brother's success.
38
+
39
+ Entering his freshman year at Jouyou Akanegaoka High School, Kyousuke vows never to play soccer again. However, Miki Tsujiwaki, the captain of the girls' soccer team, and Mori Kazuto, the manager of the boys' team, recognize Kyousuke's potential and want to see his return to the game for their own reasons.
40
+
41
+ With an opportunity to play soccer again, Kyousuke must either remain steadfast in his decision to abandon the sport he once loved, or allow himself to reignite that flame to become the best striker in the world.
42
+
43
+ [Written by MAL Rewrite]",2002.0,"[{'mal_id': 4, 'type': 'anime', 'name': 'Comedy', 'url': 'https://myanimelist.net/anime/genre/4/Comedy'}, {'mal_id': 36, 'type': 'anime', 'name': 'Slice of Life', 'url': 'https://myanimelist.net/anime/genre/36/Slice_of_Life'}, {'mal_id': 30, 'type': 'anime', 'name': 'Sports', 'url': 'https://myanimelist.net/anime/genre/30/Sports'}]","[{'mal_id': 77, 'type': 'anime', 'name': 'Team Sports', 'url': 'https://myanimelist.net/anime/genre/77/Team_Sports'}]",[]
44
+ 8,18,https://myanimelist.net/anime/18/Initial_D_Fourth_Stage,,Initial D Fourth Stage,24,Finished Airing,False,27 min per ep,PG-13 - Teens 13 or older,8.16,410,1271,"Takumi Fujiwara finally joins Ryousuke and Keisuke Takahashi to create ""Project D."" Their goal is twofold: Ryousuke wants to develop his ""High-Speed Street Racing Theory,"" while Keisuke and Takumi aim at improving their driving skills by facing powerful opponents on dangerous roads. The idea of Project D is to challenge street racing teams from other prefectures to improve both their uphill and downhill records. In order to attract the attention of the best racing teams, Ryousuke creates a dedicated website to announce the future battles of Project D and post the team's results.
45
+
46
+ The fourth season of Initial D details the hardships and successes of the members of Project D as they try to become the best street racing team outside of Gunma Prefecture.
47
+
48
+ [Written by MAL Rewrite]",2004.0,"[{'mal_id': 1, 'type': 'anime', 'name': 'Action', 'url': 'https://myanimelist.net/anime/genre/1/Action'}, {'mal_id': 8, 'type': 'anime', 'name': 'Drama', 'url': 'https://myanimelist.net/anime/genre/8/Drama'}]","[{'mal_id': 3, 'type': 'anime', 'name': 'Racing', 'url': 'https://myanimelist.net/anime/genre/3/Racing'}]","[{'name': 'Crunchyroll', 'url': 'http://www.crunchyroll.com/series-282741'}, {'name': 'Funimation', 'url': 'https://www.funimation.com/shows/initial-d'}, {'name': 'Shahid', 'url': 'https://shahid.mbc.net/en/series/Initial-D:-Fourth-Stage/series-908421'}]"
49
+ 9,19,https://myanimelist.net/anime/19/Monster,,Monster,74,Finished Airing,False,24 min per ep,R+ - Mild Nudity,8.88,24,136,"Dr. Kenzou Tenma, an elite neurosurgeon recently engaged to his hospital director's daughter, is well on his way to ascending the hospital hierarchy. That is until one night, a seemingly small event changes Dr. Tenma's life forever. While preparing to perform surgery on someone, he gets a call from the hospital director telling him to switch patients and instead perform life-saving brain surgery on a famous performer. His fellow doctors, fiancée, and the hospital director applaud his accomplishment; but because of the switch, a poor immigrant worker is dead, causing Dr. Tenma to have a crisis of conscience.
50
+
51
+ So when a similar situation arises, Dr. Tenma stands his ground and chooses to perform surgery on the young boy Johan Liebert instead of the town's mayor. Unfortunately, this choice leads to serious ramifications for Dr. Tenma—losing his social standing being one of them. However, with the mysterious death of the director and two other doctors, Dr. Tenma's position is restored. With no evidence to convict him, he is released and goes on to attain the position of hospital director.
52
+
53
+ Nine years later when Dr. Tenma saves the life of a criminal, his past comes back to haunt him—once again, he comes face to face with the monster he operated on. He must now embark on a quest of pursuit to make amends for the havoc spread by the one he saved.
54
+
55
+ [Written by MAL Rewrite]",2004.0,"[{'mal_id': 8, 'type': 'anime', 'name': 'Drama', 'url': 'https://myanimelist.net/anime/genre/8/Drama'}, {'mal_id': 7, 'type': 'anime', 'name': 'Mystery', 'url': 'https://myanimelist.net/anime/genre/7/Mystery'}, {'mal_id': 41, 'type': 'anime', 'name': 'Suspense', 'url': 'https://myanimelist.net/anime/genre/41/Suspense'}]","[{'mal_id': 50, 'type': 'anime', 'name': 'Adult Cast', 'url': 'https://myanimelist.net/anime/genre/50/Adult_Cast'}, {'mal_id': 40, 'type': 'anime', 'name': 'Psychological', 'url': 'https://myanimelist.net/anime/genre/40/Psychological'}]",[]
recommend.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cohere
2
+ import os
3
+ import pinecone
4
+ import pandas as pd
5
+ import numpy as np
6
+ from dotenv import dotenv_values
7
+
8
+ env_name = ".env"
9
+ config = dotenv_values(env_name)
10
+
11
+ co = cohere.Client(os.environ['cohere_api'])
12
+
13
+ pinecone.init(
14
+ api_key= config['pinecone_api'],
15
+ environment= config['pinecone_env']
16
+ )
17
+
18
+ index = pinecone.Index(config['pinecone_index'])
19
+
20
+
21
+
22
+ def embed_text(text):
23
+ embeddings = co.embed(
24
+ texts=[text],
25
+ model='embed-english-v3.0',
26
+ input_type='search_query'
27
+ )
28
+
29
+ return embeddings
30
+
31
+
32
+
33
+ def vector_search(desc):
34
+
35
+ results = []
36
+
37
+ embeddings = co.embed(
38
+ texts=[desc],
39
+ model='embed-english-v3.0',
40
+ input_type='search_query'
41
+ )
42
+
43
+ res = index.query([embeddings.embeddings[0]], top_k=2, include_metadata=True)
44
+
45
+ for match in res['matches']:
46
+ results.append(match['metadata']['text'])
47
+
48
+ return results
49
+
50
+ def get_anime(res):
51
+ data = pd.read_csv('mini_data.csv')
52
+
53
+ df = pd.DataFrame()
54
+
55
+ for desc in res:
56
+ anime = data[data['description'] == desc]
57
+
58
+ df = pd.concat([df, anime])
59
+
60
+ return df
requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ requests
2
+ pathlib
3
+ pandas
4
+ python-dotenv
5
+ langchain
6
+ openai
7
+ docarray
8
+ tiktoken
9
+ cohere
10
+ pinecone-client