BDE / app.py
savioratharv's picture
Upload 2 files
b919752 verified
import re
from collections import defaultdict
import gradio as gr
import pandas as pd
def create_recommendation_system(pairs):
sets_by_length = defaultdict(list)
for pair in pairs:
sets_by_length[len(pair)].append(set(pair))
sorted_keys = sorted(sets_by_length.keys(), reverse=True)
def recommend(restaurant):
recommended = set()
for length in sorted_keys:
for rest_set in sets_by_length[length]:
if restaurant in rest_set:
recommended.update(rest_set - {restaurant})
return list(recommended)
return recommend
def recommend(input_string):
f = open("task1_output_n_c1_sup4 (2).txt", "r")
data = f.read()
data = data.split("Frequent Itemsets:")
clean_string = re.sub(r'\n', '', data[1])
pattern = r"\([^\)]+\)"
extracted_tuples = re.findall(pattern, clean_string.replace("'", ""))
tuple_list = [tuple(s.strip('()').split(', ')) for s in extracted_tuples]
recommendation_system = create_recommendation_system(tuple_list)
output_list = recommendation_system(input_string)
images_labels = [("https://logowik.com/content/uploads/images/aw-restaurants5299.jpg", "A&W Restaurant"),
("https://inspirebrands.com/wp-content/uploads/2017/10/Arbys.jpg","Arbys"),
("https://www.shutterstock.com/image-vector/vinnytsia-ukraine-october-8-2023-600nw-2372329457.jpg","Burger King"),
("https://static.wixstatic.com/media/cc8696_2f0a91e1d9d245efa98b100adfcdd887~mv2.png/v1/crop/x_0,y_0,w_242,h_71/fill/w_339,h_94,al_c,lg_1,q_85,enc_auto/logo.png","California Kitchen"),
("https://logos-world.net/wp-content/uploads/2022/11/Carls-Jr.-Logo-500x281.png","Carls Jr."),
("https://upload.wikimedia.org/wikipedia/commons/thumb/0/02/Chick-fil-A_Logo.svg/873px-Chick-fil-A_Logo.svg.png","Chick-Fil-A"),
("https://upload.wikimedia.org/wikipedia/en/thumb/3/38/CECLogo2019.svg/330px-CECLogo2019.svg.png","Chuck E. Cheese"),
("https://upload.wikimedia.org/wikipedia/commons/thumb/c/cc/Culver%27s_logo.svg/558px-Culver%27s_logo.svg.png","Culvers"),
("https://upload.wikimedia.org/wikipedia/commons/thumb/a/ae/Dairy_Queen_logo.svg/300px-Dairy_Queen_logo.svg.png", "Dairy Queen"),
("https://logowik.com/content/uploads/images/493_dominospizza.jpg", "Dominos Pizza"),
("https://logos-world.net/wp-content/uploads/2023/03/Five-Guys-Logo-500x281.png", "Five Guys"),
("https://entrackr.com/storage/2023/06/Good-Flippin.jpg", "Good Flippin Burger"),
("https://logowik.com/content/uploads/images/hardees4024.jpg", "Hardees"),
("https://logos-marques.com/wp-content/uploads/2023/04/In-N-Out-Burger-Logo-768x432.png", "In-N-Out"),
("https://logos-world.net/wp-content/uploads/2022/08/Jack-in-the-Box-Logo-500x281.png", "Jack in the Box"),
("https://1000logos.net/wp-content/uploads/2021/05/Jollibee-logo-768x432.png", "Jollibee"),
("https://logowik.com/content/uploads/images/674_kfc.jpg", "KFC"),
("https://visitguernseycounty.com/wp-content/uploads/2022/05/Little-Caesars-Logo-1024x576.jpg", "Little Caesars"),
("https://logowik.com/content/uploads/images/mcdonalds-icon.jpg", "McDonalds"),
("https://images.squarespace-cdn.com/content/v1/53a47e51e4b0e78ae9ed2e97/4b8df8ab-662a-4381-92a6-97839099d5a7/Papa-Johns-logo.jpg", "Papa Johns"),
("https://cdn.nwe.io/files/x/d5/cc/c9810c9ad13188a3e0b2bc6577d7.jpg", "Pizza Inn"),
("https://logowik.com/content/uploads/images/294_pizza_hut_new_logo.jpg", "Pizza hut"),
("https://upload.wikimedia.org/wikipedia/commons/a/a6/PizzaExpress_Logo.jpg", "PizzaExpress"),
("https://images.squarespace-cdn.com/content/v1/53a47e51e4b0e78ae9ed2e97/be0aea01-84cc-4b89-a5e8-314ed394dc3c/Popeyes+logo.jpg", "Popeyes"),
("https://upload.wikimedia.org/wikipedia/commons/d/d9/Original_Round_Table_Pizza_Logo.jpg", "Round Table Pizza"),
("https://logowik.com/content/uploads/images/328_sbarro.jpg", "Sbarro"),
("https://1000logos.net/wp-content/uploads/2023/04/Shake-Shack-Logo-768x432.png", "Shake Shack"),
("https://upload.wikimedia.org/wikipedia/en/thumb/6/6d/Shakey%27s_US_logo.svg/330px-Shakey%27s_US_logo.svg.png", "Shakeys Pizza"),
("https://upload.wikimedia.org/wikipedia/commons/thumb/f/ff/SONIC_New_Logo_2020.svg/1199px-SONIC_New_Logo_2020.svg.png", "Sonic"),
("https://images.getbento.com/accounts/236fb3743b9522eafb90c6d2d20b8115/media/accounts/media/V1G5LTCrSDqyixbNUDpr_logo-tasty-burger.png", "Tasty burger"),
("https://cdn.worldvectorlogo.com/logos/uno-pizzeria.svg", "Uno Pizzeria"),
("https://upload.wikimedia.org/wikipedia/commons/thumb/2/28/Wahlburgers_Logo.svg/768px-Wahlburgers_Logo.svg.png", "Wahlburgers"),
("https://logowik.com/content/uploads/images/866_wendys.jpg", "Wendys"),
("https://logowik.com/content/uploads/images/whataburger8433.jpg", "Whataburger"),
("https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTsUZPMFzUmACfaeSrMSZsgGn5gnbXNyYRPxIrS1PfCrFWI9QJhrlkmdG9IhFbi", "White Castle")]
output = []
for i in images_labels:
if(i[1] in output_list):
output.append(i)
return output
sorted_unique_restaurants = [
'A&W Restaurant',
'Arbys',
'Burger King',
'California Kitchen',
'Carls Jr.',
'Chick-Fil-A',
'Chuck E. Cheese',
'Culvers',
'Dairy Queen',
'Dominos Pizza',
'Five Guys',
'Good Flippin Burger',
'Hardees',
'In-N-Out',
'Jack in the Box',
'Jollibee',
'KFC',
'Little Caesars',
'McDonalds',
'Papa Johns',
'Pizza Inn',
'Pizza hut',
'PizzaExpress',
'Popeyes',
'Round Table Pizza',
'Sbarro',
'Shake Shack',
'Shakeys Pizza',
'Sonic',
'Tasty burger',
'Uno Pizzeria',
'Wahlburgers',
'Wendys',
'Whataburger',
'White Castle']
io = gr.Interface(fn=recommend, inputs=gr.Dropdown(choices=sorted_unique_restaurants, value="Burger King"), outputs=gr.Gallery(label="Generated images", show_label=False, elem_id="gallery", columns=[4], object_fit="contain", height="auto"), title='Restaurant Recommender System', description='Find your ideal restaurant')
io.queue().launch(share = True, debug = True)