Spaces:
Runtime error
Runtime error
File size: 7,185 Bytes
60a65c8 833bde7 60a65c8 631b6fd 60a65c8 9bcb911 60a65c8 4ec6379 60a65c8 833bde7 60a65c8 |
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
import gradio as gr
import torch, numpy as np, pandas as pd
import skimage
import pickle
defaultColumns = ['movieId', 'rating']
movies_df = pd.read_csv("./csv/movies.csv")
ratings_df = pd.read_csv("./csv/ratings.csv")
options = [
"Toy Story (1995)",
"Jumanji (1995)",
"Dracula: Dead and Loving It (1995)",
"Babe (1995)",
"Captain Marvel (2018)",
"Avengers: Infinity War - Part I (2018)",
"Avengers: Infinity War - Part II (2019)",
"Thor: Ragnarok (2017)",
"Guardians of the Galaxy 2 (2017)",
"Captain America: Civil War (2016)",
"Doctor Strange (2016)",
"X-Men: Apocalypse (2016)",
"Untitled Spider-Man Reboot (2017)",
"Manolito Four Eyes (1999)",
"El Robobo De La Jojoya (1991)",
"Elsa & Fred (2014)",
"Soccer Days (2003)",
"Too Late Blues (1961)",
"Melbourne (2014)",
"Clear History (2013)",
"The Identical (2014)",
"The Trans-Atlantic Mystery (1932)",
"The Gamers: Hands of Fate (2013)",
"Love at First Fight (2014)",
"Mare Nostrum (1926)",
"Ring Of The Musketeers (1992)",
"Skylark (1941)",
"The Pagan (1929)",
"Scorpio One (1998)",
"The Chinese Ring (1947)",
"The Power and the Prize (1956)",
"The Gambler Returns: The Luck Of The Draw (1991)",
"Smart Blonde (1937)",
"The Affairs of Annabel (1938)",
"Montana Belle (1952)",
"The Clown (1953)",
"In the Blood (2006)",
"Pound of Flesh (2010)",
"The Chicken Chronicles (1977)",
"Lizzie (1957)",
"Magic Boy (1961)",
"Shadow Zone: The Undead Express (1996)",
"Someone To Love (1988)",
"I Found Stella Parish (1935)",
"The Savage Seven (1968)",
"The Decks Ran Red (1958)",
"Man on Fire (1957)",
"Life Begins (1932)",
"The Last of Mrs. Cheyney (1929)",
"One More Time (1970)",
"I Don't Buy Kisses Anymore (1992)",
"Night Unto Night (1949)",
"Heidi (1952)",
"Hammersmith Is Out (1972)",
"The Daughter of Rosie O'Grady (1950)",
"Sidewalks of New York (1931)",
"Mary Stevens M.D. (1933)",
"The Prize (2011)",
"Secrets of an Actress (1938)",
"Man Made Monster (1941)",
"Horror Island (1941)",
"Sealed Lips (1942)",
"Tangier (1946)",
"Aces Go Places V: The Terracotta Hit (1989)",
"Pagan Love Song (1950)",
"The Racers (1955)",
"The Oklahoman (1957)",
"The Golden Age of Comedy (1957)",
"Stalingrad (1989)",
"The Tsunami and the Cherry Blossom (2011)",
"The Power Within (1995)",
"No Greater Glory (1934)",
"Goodbye, Mr. President (1987)",
"Sankofa (1993)",
"Teza (2008)",
"The Mystery of Mr. X (1934)",
"Midnight Heat (1996)",
"Red Dust (1990)",
"In the Presence of Mine Enemies (1997)",
"Talk About a Stranger (1952)",
"The Newcomers (2000)",
"Right Cross (1950)",
"Heidi (1993)",
"The Miracle Worker (2000)",
"The Return of Sabata (1971)",
"The McKenzie Break (1970)",
"Mercy (2010)",
"Happily N'Ever After 2 (2009)",
"Left for Dead (2007)",
"Hotel (2004)",
"The Hearse (1980)",
"Infection (2005)",
"Voyage of the Unicorn (2001)",
"The Geisha Boy (1959)",
"The Phantom of the Opera (1990)",
"P.U.N.K.S (1999)",
"When a Man Falls (2007)",
"Springfield Rifle (1952)",
"Why Be Good? (1929)",
"The American Success Company (1980)",
"The Expedition to the End of the World (2014)",
"Jealousy (2013)",
"Magic Kid II (1994)",
"The Radio Burglary (1951)",
"A Dangerous Place (1995)",
"Magic Kid (1993)",
"Sin Takes a Holiday (1930)",
"Hoodlum Priest (1961)",
"Street Girl (1929)",
"The Fleet's In (1942)",
"The Divine Woman (1928)",
"The Sundowners (1950)",
"The Real Howard Spitz (1998)",
"Mrs. O'Malley and Mr. Malone (1950)",
"Sierra (1950)",
"The Gangster (1947)",
"Metamorphosis (2007)",
"Russkies (1987)",
"Julius Caesar (1971)",
"Hercules and the Lost Kingdom (1994)",
"Rites of Passage (2012)",
"The Suspect (2013)",
"Mongolian Death Worm (2010)",
"Winter Break (2003)",
"The Facility (2012)",
"Shredderman Rules (2007)",
"Man on Fire (1987)",
"Piranha Hunt (2006)",
"Trouble Along the Way (1953)",
"The Secret Agent Club (1996)",
"I'm in Love with a Church Girl (2013)",
"Ironclad 2: Battle for Blood (2014)",
"Voices (2007)",
"The Land Before Time XI: Invasion of the Tinysauruses (2005)",
"See Girl Run (2013)",
"Ritual (2002)",
"Head Office (1985)",
"Jim Jefferies: I Swear to God (2009)",
"Social Nightmare (2013)",
"Once Fallen (2010)",
"Lease of Life (1954)",
"The Magic Box (1951)",
"Captain Boycott (1947)",
"The Adventures of Tartu (1943)",
"Knight Without Armor (1937)",
"Suddenly (2006)",
"Winning Streak (2012)",
"The Slaughter (2006)",
"The Flesh and the Fiends (1961)",
"The Lion Has Wings (1939)",
"Sanders of the River (1935)",
"Counter-Attack (1945)",
"The Macomber Affair (1947)",
"A Woman's Vengeance (1948)",
"Cry, the Beloved Country (1952)",
"Address Unknown (1944)",
"Drums in the Deep South (1951)",
"The Great Man (1956)",
"I Accuse! (1958)",
"State Fair (1962)",
"Kill Katie Malone (2010)",
"The First of the Few (1942)",
"The Sacketts (1979)",
"Rio Conchos (1964)",
"Hercules and the Circle of Fire (1994)",
"Clawed: The Legend of Sasquatch (2005)",
"June Bride (1948)",
"Without Reservations (1946)",
"Katherine (1975)",
"Conspiracy: The Trial of the Chicago 8 (1987)",
"Descending Angel (1990)",
"Roswell (1994)",
"The Ballad of Lucy Whipple (2001)",
"Taken (2002)",
"Crown Heights (2004)",
"Marianne (1929)",
"They Fought for Their Motherland (1975)",
"Welcome to Hard Times (1967)",
"The Lost Continent (1968)",
"The Incredible 2-Headed Transplant (1971)",
"Scared to Death (1947)",
"Scrooge (1935)",
"Knife Fight (2013)",
"Suddenly (2013)",
"Tornado! (1996)",
"The Opposite Sex (1956)",
"Mischief Night (2013)",
"Saratoga (1937)",
"Legendary: Tomb of the Dragon (2013)",
"Red Riding Hood (2006)",
"Sea Beast (2008)",
"Hitler: The Last Ten Days (1973)",
"The Man From The Alamo (1953)",
"Hard Ride to Hell (2010)",
"End of the World (1931)",
"Lucrèce Borgia (1935)",
"Un grand amour de Beethoven (1936)",
"I Accuse (1938)",
"Tower of Nesle (1955)",
"The Battle of Austerlitz (1960)",
"Cyrano et D'Artagnan (1964)",
]
with open("model.pkl", "rb") as f:
model = pickle.load(f)
def recomendacao(filme, nota):
f_filme = movies_df.loc[movies_df['title'] == filme]['movieId'].values[0]
f_nota = float(nota)
default = [
f_filme,
f_nota
]
df=pd.DataFrame([default], columns = defaultColumns)
predictions = model.predict(df)
user_rating = ratings_df.loc[ratings_df['userId'] == predictions[0]]
top_ratings = user_rating.sort_values(by='rating', ascending=False)
top_ratings = top_ratings.drop(top_ratings[top_ratings['movieId'] == f_filme].index)
top_movies = top_ratings.head(5)['movieId'].tolist()
recomendacoes = []
for movie_id in top_movies:
movie = movies_df.loc[movies_df['movieId'] == movie_id]
title = movie['title'].values[0]
recomendacoes.append(title)
recomendacoes
result = '1 - ' + recomendacoes[0] + ';\n' + '2 - ' + recomendacoes[1] + ';\n' +'3 - ' + recomendacoes[2] + ';\n' +'4 - ' + recomendacoes[3] + ';\n' +'5 - ' + recomendacoes[4] + '.\n'
return result
iface = gr.Interface(
fn=recomendacao,
title="Data Mining",
allow_flagging="never",
inputs=[
gr.Dropdown(options, label="Filme", info="Escolha o nome de um filme"),
gr.Slider(0, 5, value=0, label="Rating", info="Dê uma nota entre 0 e 5"),
],
outputs="text")
iface.launch() |