1 Star 0 Fork 2

佐佐/MoviesAnalysingSystem

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
app.py 11.38 KB
一键复制 编辑 原始数据 按行查看 历史
lonelyinnovator 提交于 2022-06-24 10:49 . 最终版本
from flask import Flask, render_template, request, url_for
import sqlite3
from urllib import parse
from makeBody.areas_treemap import get_areas_treemap
from makeBody.areas_pie import get_areas_pie
from makeBody.genres_funnel import get_genres_funnel
from makeBody.genres_wordcloud import get_genres_wordcloud
from makeBody.score_top import get_score_top
from makeBody.comment_top import get_comment_top
from makeBody.score import get_score
from makeBody.heatmap import showtime_distribution
from makeBody.scatter import draw_scatter
from makeBody.film_search import get_film_search
from makeBody.showtime_genres import select_showtime as showtime_genres_select_showtime
from makeBody.showtime_genres import get_showtime_genres
from makeBody.gauge_score import select_showtime as gauge_score_select_showtime
from makeBody.gauge_score import get_gauge_score
from makeBody.liquid_filmNumber import select_showtime as liquid_filmNumber_select_showtime
from makeBody.liquid_filmNumber import get_liquid_filmNumber
from makeBody.radar_year import select_showtime as radar_year_select_showtime
from makeBody.radar_year import get_redar_year
from makeBody.emotion_analysis import get_emotion_analysis
from makeBody.emotion_analysis import get_filmnames
from makeBody.map_world import get_map_world
from makeBody.table_all import get_table_datas as table_all_get_table_datas
from BoxOfficePrediction.boxoffice_predictor import Predictor, MovieData
from Movie_Recommender.recommender import recommender
from SentimentAnalysis.predict import predict
from SentimentAnalysis.visualize import generate_liquid_figure
from SentimentAnalysisbyLSTM.last import test
import json
# 解决跨域问题
def after_request(response):
# 8080为vue端口
response.headers['Access-Control-Allow-Origin'] = request.headers.get('Origin') or 'http://127.0.0.1:8080'
response.headers['Access-Control-Allow-Methods'] = 'PUT,GET,POST,DELETE'
response.headers['Access-Control-Allow-Headers'] = 'Content-Type,Authorization,Accept,Origin,Referer,User-Agent'
response.headers['Access-Control-Allow-Credentials'] = 'true'
return response
app = Flask(__name__)
app.after_request(after_request)
# 票房预测
predictor = Predictor()
@app.route('/pred', methods=['POST'])
def box_office_prediction():
"""票房预测"""
if request.method == 'POST':
json_data = json.loads(request.get_data().decode('utf-8'))
print(json_data)
try:
movie_data = MovieData.from_dict(json_data)
return str(predictor.predict_data(movie_data))
except Exception as e:
print(e)
return 'failed'
return 'failed'
@app.route('/recom', methods=['POST'])
def movie_recommend():
"""电影推荐"""
if request.method == 'POST':
json_data = json.loads(request.get_data().decode('utf-8'))
# print(json_data)
re = recommender()
result = re.movie_recommender(json_data['movie_name'], int(json_data['movie_num']))
result = [i.to_numpy()[0] for i in result]
print(result)
return json.dumps({'movies': result})
# for i in result:
# print(i.to_numpy())
# print(type(i))
# print(len(result))
# print(result)
# json.dumps()
# movie_data = MovieData.from_dict(json_data)
# return str(predictor.predict_data(movie_data))
return 'failed'
@app.route("/senti", methods=['POST'])
def sentiment_analyse():
"""情感分析"""
if request.method == 'POST':
json_data = json.loads(request.get_data().decode('utf-8'))
print(json_data['content'])
# 情感分析预测,得到0~1之间的结果
senti = predict(json_data['content'])
# print(senti)
# generate_liquid_figure(senti)
return json.dumps({'sentiment': str(senti)})
return 'failed'
# 登录界面
@app.route('/', methods=['GET'])
def login():
return render_template("makeHeader/home.html", url_none=url_for('home_url'))
# 首页
@app.route('/home')
def home():
return render_template("makeHeader/home.html", url_none=url_for('home_url'))
@app.route("/home_url")
def home_url():
# get_map_world()
return render_template('makeBody/map_world.html')
# 2
# areas_treemap 矩形树图
@app.route('/areas_treemap')
def areas_treemap():
return render_template("makeHeader/url_none.html", url_none=url_for('areas_treemap_url'))
@app.route("/areas_treemap_url")
def areas_treemap_url():
# get_areas_treemap()
return render_template('makeBody/areas_treemap.html')
# areas_pie 饼图
@app.route('/areas_pie')
def areas_pie():
return render_template("makeHeader/url_none.html", url_none=url_for('areas_pie_url'))
@app.route("/areas_pie_url")
def areas_pie_url():
# get_areas_pie()
return render_template('makeBody/areas_pie.html')
# 3
# genres_funnel 漏斗图
@app.route('/genres_funnel')
def genres_funnel():
return render_template("makeHeader/url_none.html", url_none=url_for('genres_funnel_url'))
@app.route("/genres_funnel_url")
def genres_funnel_url():
# get_genres_funnel()
return render_template('makeBody/genres_funnel.html')
# genres_wordcloud 词云图
@app.route('/genres_wordcloud')
def genres_wordcloud():
return render_template("makeHeader/url_none.html", url_none=url_for('genres_wordcloud_url'))
@app.route("/genres_wordcloud_url")
def genres_wordcloud_url():
# get_genres_wordcloud()
return render_template('makeBody/genres_wordcloud.html')
# 4
# score_top 时间轴图+柱状图
@app.route('/score_top')
def score_top():
return render_template("makeHeader/url_none.html", url_none=url_for('score_top_url'))
@app.route("/score_top_url")
def score_top_url():
# get_score_top()
return render_template('makeBody/score_top.html')
# 5
# comment_top 时间轴图+饼图
@app.route('/comment_top')
def comment_top():
return render_template("makeHeader/url_none.html", url_none=url_for('comment_top_url'))
@app.route("/comment_top_url")
def comment_top_url():
# get_comment_top()
return render_template('makeBody/comment_top.html')
# 6
# score 折线图
@app.route('/score')
def score():
return render_template("makeHeader/url_none.html", url_none=url_for('score_url'))
@app.route("/score_url")
def score_url():
# get_score()
return render_template('makeBody/score.html')
# 7
# heatmap 热力图
@app.route('/heatmap')
def heatmap():
return render_template("makeHeader/url_none.html", url_none=url_for('heatmap_url'))
@app.route("/heatmap_url")
def heatmap_url():
# showtime_distribution()
return render_template('makeBody/heatmap.html')
# 8
# scatter 散点图
@app.route('/scatter')
def scatter():
return render_template("makeHeader/url_none.html", url_none=url_for('scatter_url'))
@app.route("/scatter_url")
def scatter_url():
# draw_scatter()
return render_template('makeBody/scatter.html')
# 9
# film_search 柱状图
search_types = []
@app.route('/film_search', methods=['GET', 'POST'])
def film_search():
search_types.clear()
search_type = request.form.get("search_type", type=str, default='主演')
search_types.append(search_type)
# print(search_type)
if (search_type != "主演"):
get_film_search(search_type)
return render_template("makeHeader/url_film_search.html", url_film_search=url_for('film_search_url'))
@app.route("/film_search_url")
def film_search_url():
# 这里利用已经生成的html,因为生成“主演”html的时间太长
# print(search_types[0])
if (search_types[0] == "主演"):
return render_template('makeBody/film_search_actors.html')
return render_template('makeBody/film_search.html')
# 10
# showtime_genres 饼图
@app.route('/showtime_genres', methods=['GET', 'POST'])
def showtime_genres():
showtime = showtime_genres_select_showtime()
showyear = request.form.get("showyear", type=int, default=2000)
# print(showyear)
get_showtime_genres(showyear)
return render_template("makeHeader/url_select_showtime.html", urlforheader="showtime_genres", showtime=showtime,
url_select_showtime=url_for('showtime_genres_url'))
@app.route("/showtime_genres_url")
def showtime_genres_url():
return render_template('makeBody/showtime_genres.html')
# 11
# gauge_score 仪表图
@app.route('/gauge_score', methods=['GET', 'POST'])
def gauge_score():
showtime = gauge_score_select_showtime()
showyear = request.form.get("showyear", type=int, default=2000)
# print(showyear)
get_gauge_score(showyear)
return render_template("makeHeader/url_select_showtime.html", urlforheader="gauge_score", showtime=showtime,
url_select_showtime=url_for('gauge_score_url'))
@app.route("/gauge_score_url")
def gauge_score_url():
return render_template('makeBody/gauge_score.html')
# 12
# liquid_filmNumber 水球图
@app.route('/liquid_filmNumber', methods=['GET', 'POST'])
def liquid_filmNumber():
showtime = liquid_filmNumber_select_showtime()
showyear = request.form.get("showyear", type=int, default=2000)
# print(showyear)
get_liquid_filmNumber(showyear)
return render_template("makeHeader/url_select_showtime.html", urlforheader="liquid_filmNumber", showtime=showtime,
url_select_showtime=url_for('liquid_filmNumber_url'))
@app.route("/liquid_filmNumber_url")
def liquid_filmNumber_url():
return render_template('makeBody/liquid_filmNumber.html')
# 13
# radar_year 雷达图
@app.route('/radar_year', methods=['GET', 'POST'])
def radar_year():
showtime = radar_year_select_showtime()
showyear = request.form.get("showyear", type=int, default=2000)
# print(showyear)
get_redar_year(showyear)
return render_template("makeHeader/url_select_showtime.html", urlforheader="radar_year", showtime=showtime,
url_select_showtime=url_for('radar_year_url'))
@app.route("/radar_year_url")
def radar_year_url():
return render_template('makeBody/radar_year.html')
# 14
# image_wordcloud 词云图
@app.route('/image_wordcloud')
def image_wordcloud():
return render_template("makeHeader/url_none.html", url_none=url_for('image_wordcloud_url'))
@app.route("/image_wordcloud_url")
def image_wordcloud_url():
return render_template('makeBody/image_wordcloud_hand.html')
# 15
# 功能实现-情感分析,饼图
# emotion_analysis
@app.route('/emotion_analysis', methods=['GET', 'POST'])
def emotion_analysis():
# movies = ["电影1","电影2","电影3"]
filmnames, dataset = get_filmnames()
print(filmnames[0])
filmname = request.form.get("filmname", type=str, default=filmnames[0])
print(filmname)
link = dataset[filmname]
# link = "https://www.imdb.com/title/tt1745960/"
get_emotion_analysis(filmname, link)
return render_template("makeHeader/url_emotion_analysis.html", filmnames=filmnames,
url_emotion_analysis=url_for('emotion_analysis_url'))
@app.route("/emotion_analysis_url")
def emotion_analysis_url():
return render_template('makeBody/emotion_analysis.html')
# 1
# 列表 table
@app.route('/table_all', methods=['GET', 'POST'])
def table_all():
score = request.form.get("score", type=str, default="全部")
area = request.form.get("area", type=str, default="全部")
# print(score)
# print(area)
movies = table_all_get_table_datas(score, area)
# print(movies)
return render_template("makeHeader/table.html", movies=movies)
if __name__ == '__main__':
app.run(debug=True, port=5000)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/zuoshiwen22/movies-analysing-system.git
git@gitee.com:zuoshiwen22/movies-analysing-system.git
zuoshiwen22
movies-analysing-system
MoviesAnalysingSystem
master

搜索帮助