Skip to content

Xinyi ai front end connect to content_based #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file added CS410 Final Project Proposal (EarlyOffer).pdf
Binary file not shown.
16 changes: 16 additions & 0 deletions autoencoder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pandas as pd

# Read in data
df1 = pd.read_csv('dataset/tmdb_5000_credits.csv')
df2 = pd.read_csv('dataset/tmdb_5000_movies.csv')
# print(df2.head(3)) # 20 columns
df2 = df2.rename(columns={'id':'movie_id'})
# print(df2.head(3))

# print(f'df2 columns: {df2.columns}')

df2=df2.merge(df1,on='movie_id') # 20 columns -> 23 columns
columnNames = df2.columns
print(f'column names:{columnNames}')
print('df2 shape before ranking:',df2.shape) #(4803, 23)
# print(df2.head(3))
Binary file added front_end/.DS_Store
Binary file not shown.
24 changes: 24 additions & 0 deletions front_end/.gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This file specifies files that are *not* uploaded to Google Cloud Platform
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
# $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore

# Python pycache:
__pycache__/
# Ignored by the build system
/setup.cfg
#python venv
.venv

#system files
.vscode
136 changes: 136 additions & 0 deletions front_end/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# system
.vscode
.venv

# sensitive
app.yaml

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
21 changes: 21 additions & 0 deletions front_end/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 tcheng10@UIUC for CS411

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
56 changes: 56 additions & 0 deletions front_end/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# A Todo List demo App
This is a todo list demo designed for CS411.
# Tutorial
<iframe width="560" height="315" src="https://www.youtube.com/embed/sY1lLGe7ECA" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

A comprehensive writeup is avaliable [here](https://tichung.com/blog/2021/20200323_flask/).

## Requirements
```
python >= 3.5
```

## Getting started
```bash
git clone https://github.com/a2975667/flask-gcp-mysql-demo.git
cd flask-gcp-mysql-demo
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
export FLASK_APP = app
flask run
```

## Setting up GCP
Create a `app.yaml` file in the root folder with the following content:
```yaml
runtime: python38 # or another supported version

instance_class: F1

env_variables:
MYSQL_USER: <user_name> # please put in your credentials
MYSQL_PASSWORD: <user_pw> # please put in your credentials
MYSQL_DB: <database_name> # please put in your credentials
MYSQL_HOST: <database_ip> # please put in your credentials

handlers:
# Matches requests to /images/... to files in static/images/...
- url: /img
static_dir: static/img

- url: /script
static_dir: static/script

- url: /styles
static_dir: static/styles
```

Setting up the deployment
```bash
curl https://sdk.cloud.google.com | bash
gcloud components install app-engine-python
gcloud config set project cs411-sp21
gcloud auth login
gcloud app deploy
```
Binary file added front_end/app/.DS_Store
Binary file not shown.
49 changes: 49 additions & 0 deletions front_end/app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Setup at app startup"""
import os
import sqlalchemy
from flask import Flask
# from yaml import load, Loader



# def init_connection_engine():
# """ initialize database setup
# Takes in os variables from environment if on GCP
# Reads in local variables that will be ignored in public repository.
# Returns:
# pool -- a connection to GCP MySQL
# """


# # detect env local or gcp
# if os.environ.get('GAE_ENV') != 'standard':
# try:
# variables = load(open("app.yaml"), Loader=Loader)
# except OSError as e:
# print("Make sure you have the app.yaml file setup")
# os.exit()

# env_variables = variables['env_variables']
# for var in env_variables:
# os.environ[var] = env_variables[var]

# pool = sqlalchemy.create_engine(
# sqlalchemy.engine.url.URL(
# drivername="mysql+pymysql",
# username=os.environ.get('MYSQL_USER'),
# password=os.environ.get('MYSQL_PASSWORD'),
# database=os.environ.get('MYSQL_DB'),
# host=os.environ.get('MYSQL_HOST')
# )
# )

# return pool


app = Flask(__name__)
# db = init_connection_engine()

# To prevent from using a blueprint, we use a cyclic import
# This also means that we need to place this import here
# pylint: disable=cyclic-import, wrong-import-position
from app import routes
42 changes: 42 additions & 0 deletions front_end/app/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# """Defines all the functions related to the database"""
from flask import render_template
from app import app
from webforms import SearchForm
import content_based_system as cb

@app.route('/content_based', methods=["POST"])
def search():
print("wtf")
form = SearchForm()
data = form.searched.data #input value
print(data)
rec_movies = cb.get_recommendations('The Dark Knight Rises')
targetItem = []
for index, movie in rec_movies:
item = {
"movie_name" : movie
}
targetItem.append(item)
return render_template(
"content_based.html",
form=form,
targetItem=targetItem
)

# conn = db.connect()
# print('SELECT * FROM Game WHERE name like "%{}%";'.format(data))
# query = conn.execute('SELECT * FROM Game WHERE name like "{}";'.format(data))
# conn.close()
# query_result = [x for x in query]
# targetItem = []
# for ret in query_result:
# item = {
# "gameId": ret[0],
# "name": ret[1],
# "year": ret[2],
# "genre": ret[3]
# }
# targetItem.append(item)
# return render_template("search.html",
# form=form,
# targetItem=targetItem)
Loading