def predict(): form = PredictionForm() if form.validate_on_submit(): flash(f'Predicted House Price for given data is {form.crim.data}!', 'success') return redirect(url_for('predict')) return render_template('predict.html', title='Predict', form=form)
def predict(): form = PredictionForm() if form.validate_on_submit(): iam_header = { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + access_token } objects = [form.month.data, form.dayofweek.data, form.borough.data, form.min_humidity.data, form.max_humidity.data, form.min_temp.data, form.max_temp.data, form.max_wind_speed.data, form.weather_description.data ] userInput = [] userInput.append(objects) payload_scoring = {"input_data": [{"fields": ["month", "dayofweek", "borough", "min_humidity", "max_humidity", "min_temp", "max_temp", "max_wind_speed", "weather_description"], "values": userInput }]} predict_value = requests.post("",json = payload_scoring , headers = iam_header) result = json.loads(predict_value.text) return result return render_template('index.html', form = form)
def predict(): form=PredictionForm() if form.validate_on_submit(): post=Post() if form.picture.data: picture_file = save_picture(form.picture.data) post.image_file = picture_file picture_path = os.path.join(app.root_path, 'static/uploaded_pics', picture_file) breed= predict_breed_transfer(picture_path) if dog_detector(picture_path): #flash('dog detected','success') #flash('Breed: '+breed,'success') post.title="Dog image detected" post.content="The breed is "+breed elif face_detector(picture_path): #flash('face detected','success') #flash('Breed: '+breed,'danger') post.title="Human image detected" post.content="The image resembles to "+breed else: flash('no face or dog detected','danger') post.title="Unknown image detected" post.content="It is neither a dog nor a human" db.session.add(post) db.session.commit() return redirect(url_for('home')) return render_template('prediction.html', title='Prediction', form=form)
def predict(): form = PredictionForm() if form.validate_on_submit(): sqft = request.form['sqft'] sqft_log = np.log(int(sqft)) baths_num = set_baths(request.form['baths_num']) beds_num = set_beds(request.form['beds_num']) story = set_story(request.form['story']) age = set_age(request.form['age']) schools_num = set_schools(request.form['schools_num']) schools_8_up = check_select(request.form['schools_8_up']) zipcode = int(request.form['zipcode']) zipcode_expensive = set_zipcode(zipcode) condo = check_select(request.form['condo']) mobile = check_select(request.form['mobile']) feature_names = [ 'sqft_log', 'zipcode_expensive', 'zipcode', 'age', 'baths_num', 'schools_8_up', 'story', 'Condo', 'beds_num', 'schools_num', 'mobile' ] work_features = [ sqft_log, zipcode_expensive, zipcode, age, baths_num, schools_8_up, story, condo, beds_num, schools_num, mobile ] x_test = pd.DataFrame([work_features], columns=feature_names) x_test = scaler.transform(x_test) price = predict_price(x_test) flash(f'Прогнозируемая цена {price} $', 'success') return render_template('predict.html', title='Predict', form=form)
def index_page(): """ """ global data, columns, dict_val, dataframe form = PredictionForm() if form.validate_on_submit(): # creating a dataframe with the input values for val in form: if val.id in columns: # if the value categorical if val.id in data: # obtaining the labeled id temp_val = data[val.id].index(val.data) idx = columns.index(val.id) dict_val[idx] = temp_val else: idx = columns.index(val.id) dict_val[idx] = val.data print(dict_val) arr = [val for val in dict_val.values()] arr = np.array([arr]) df = pd.DataFrame(arr, columns=columns) dataframe = df print(df) flash(f"prediction completed!", 'success') return redirect(url_for('prediction')) return render_template('index.html', form=form)
def predict(): form = PredictionForm() if form.validate_on_submit(): brand = request.form['mark'] bodyType = request.form['bodyType'] fuelType = request.form['fuelType'] productionDate = request.form['productionDate'] modelDate = request.form['modelDate'] numberOfDoors = request.form['numberOfDoors'] vehicleTransmission = request.form['vehicleTransmission'] engineDisplacement = request.form['engineDisplacement'] enginePower = define_power_category(request.form['enginePower']) mileage = define_mileage_category(request.form['mileage']) drive = request.form['drive'] owners = request.form['owners'] empty_features = [0] * 45 with open('features.list', 'r') as filehandle: features = json.load(filehandle) work_features = [ bodyType, brand, fuelType, modelDate, numberOfDoors, productionDate, vehicleTransmission, engineDisplacement, enginePower, mileage, drive, owners ] df = pd.DataFrame([work_features + empty_features], columns=features) price = predict_price(df) write_logs(work_features, features[:12], price) flash(f'Цена автомобиля {form.mark.data.upper()} {price} руб.', 'success') return render_template('predict.html', title='Predict', form=form)
def data(): form = PredictionForm() if form.validate_on_submit(): flower = Flower(sl=form.sl.data, sw=form.sw.data, pl=form.pl.data, pw=form.pw.data) db.session.add(flower) db.session.commit() return redirect(url_for('predict')) return render_template('data.html', form=form)
def data(): form = PredictionForm() if form.validate_on_submit(): #flower = Flower(sl=form.sl.data, sw=form.sw.data, pl=form.pl.data, pw=form.pw.data) promote = Promotion(dep=form.dep.data, reg=form.reg.data, edu=form.edu.data, gen=form.gen.data, rec=form.rec.data, trn=form.trn.data, age=form.age.data, rat=form.rat.data, srv=form.srv.data, kpi=form.kpi.data, awd=form.awd.data, scr=form.scr.data) db.session.add(promote) db.session.commit() return redirect(url_for('predict')) return render_template('data.html', form=form)
def home(request): context = {} if request.user.is_anonymous(): now = datetime.datetime.now() blog_date = blog_title = blog_content = None competition = Competition.objects\ .filter(start_date__lt=now, close_date__gt=now)\ .order_by('start_date') if competition: competition = competition[0] predictions = Prediction.objects\ .filter(competition=competition)\ .all()[:10] else: competition = None predictions = None context['blog_date'] = blog_date context['blog_title'] = blog_title context['blog_content'] = blog_content context['competition'] = competition context['predictions'] = predictions if request.method == "POST": # login attempt if request.POST.get('login', ''): username = request.POST['email'] password = request.POST['password'] user = authenticate(username=username, password=password) if user and not user.is_anonymous(): login(request, user) return redirect(reverse('home')) else: error = "Sorry, your details weren't recognised" context = {'error': error} return redirect(addToQueryString(reverse('home'), context)) else: # signup attempt form = PredictionForm(request.POST, request.FILES) if form.is_valid(): prediction = form.save() request.session['prediction'] = prediction request.session['competition'] = competition return redirect(reverse('signup')) else: context['form'] = form else: # default homepage context['form'] = PredictionForm() return render_with_context(request, 'home.html', context) else: return redirect(reverse('logged_in'))
def predict(): form = PredictionForm() select_options = [(key, value) for key, value in form_select.items()] form.team.choices = select_options form.opp.choices = select_options return render_template("prediction_model.html", form=form)
def prediction_submit(): """Provide HTML form to submit a prediction.""" Trending = get_TT() form = PredictionForm(request.form) if request.method == 'POST' and form.validate(): # whatever we do with text etc text = form.text.data return redirect(url_for('prediction_made', text=text)) TT_nohas = [] for i in range(0, 10): if ("#" in Trending[i]): TT_nohas.append(Trending[i].strip('#')) else: TT_nohas.append(Trending[i]) return render_template('prediction/submit.html', form=form, TT=Trending, TTno=TT_nohas)
def index(): form = PredictionForm() return render_template('index.html', form = form)
def predict(): form = PredictionForm() if form.submit(): # flash("Working",'success') header = { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + "eyJraWQiOiIyMDIwMDYyNDE4MzAiLCJhbGciOiJSUzI1NiJ9.eyJpYW1faWQiOiJpYW0tU2VydmljZUlkLTAxYmQwYmRhLWY2YmMtNDY0Yy1iMzA0LTI5MzUyZTlhZDA2ZSIsImlkIjoiaWFtLVNlcnZpY2VJZC0wMWJkMGJkYS1mNmJjLTQ2NGMtYjMwNC0yOTM1MmU5YWQwNmUiLCJyZWFsbWlkIjoiaWFtIiwiaWRlbnRpZmllciI6IlNlcnZpY2VJZC0wMWJkMGJkYS1mNmJjLTQ2NGMtYjMwNC0yOTM1MmU5YWQwNmUiLCJuYW1lIjoiU2VydmljZSBjcmVkZW50aWFscy0xIiwic3ViIjoiU2VydmljZUlkLTAxYmQwYmRhLWY2YmMtNDY0Yy1iMzA0LTI5MzUyZTlhZDA2ZSIsInN1Yl90eXBlIjoiU2VydmljZUlkIiwiYWNjb3VudCI6eyJ2YWxpZCI6dHJ1ZSwiYnNzIjoiMjU2YWU1YjVmZjcxNGRiZDhjMDU1MDBhYjAxZTViNWMifSwiaWF0IjoxNTkzNDQ0MTY4LCJleHAiOjE1OTM0NDc3NjgsImlzcyI6Imh0dHBzOi8vaWFtLmJsdWVtaXgubmV0L2lkZW50aXR5IiwiZ3JhbnRfdHlwZSI6InVybjppYm06cGFyYW1zOm9hdXRoOmdyYW50LXR5cGU6YXBpa2V5Iiwic2NvcGUiOiJpYm0gb3BlbmlkIiwiY2xpZW50X2lkIjoiZGVmYXVsdCIsImFjciI6MSwiYW1yIjpbInB3ZCJdfQ.1d60axMyD9AZrZge3p_WHQsdfBH2EAqQs1k4B56uA8Gnn2VXJ3qnZS3cLCpBku2gj_Z2XY4FSlLa3TH3Aa98GZzM_FPsKzr-AVHvdA4Xa_sHq4w7Zg-MCniKE-l6_5_mHMJHNcpeVvhKOX2UqRU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WktAQvXAdR0uL3l-d6IG-YWxnDxbHMNIcu1U0WAlzrCQzQHFYCuKsKOPclc5K2rvU88M-LsrvM60QPkbywx4_oAunkP7ArimKHmAbWfM5dj4pMTp51-VfaULhWydJvy4r3dBDEMrWbVRQuUikfW4p0DHx_ehQI6aBUquxTcFe7A", 'ML-Instance-ID': "28607ee8-f59c-42a8-87e7-5941b3198461 " } if (form.country.data == None): python_object = [] else: python_object = [ form.country.data, form.year.data, form.status.data, form.adult_mortality.data, form.infant_deaths.data, form.alcohol.data, form.percentage_expenditure.data, form.hepatitis_b.data, form.measles.data, form.bmi.data, form.under_five_deaths.data, form.polio.data, form.total_expenditure.data, form.diphtheria.data, form.hiv.data, form.gdp.data, form.population.data, form.thinness_1_to_19_years.data, form.thinness_5_to_9_years.data, form.income.data, form.schooling.data ] #Transform python objects to Json userInput = [] userInput.append(python_object) # NOTE: manually define and pass the array(s) of values to be scored in the next line payload_scoring = { "input_data": [{ "fields": [ "Country", "Year", "Status", "Adult Mortality", "infant deaths", "Alcohol", "percentage expenditure", "Hepatitis B", "Measles ", " BMI ", "under-five deaths ", "Polio", "Total expenditure", "Diphtheria ", " HIV/AIDS", "GDP", "Population", " thinness 1-19 years", " thinness 5-9 years", "Income composition of resources", "Schooling" ], "values": userInput }] } response_scoring = requests.post( 'https://eu-gb.ml.cloud.ibm.com/v4/deployments/0447057f-d7e7-47b0-a45e-3c33baedd315/predictions', json=payload_scoring, headers=header) print("Scoring response") print(json.loads(response_scoring.text)) response_scoring = requests.post( "https://eu-gb.ml.cloud.ibm.com/v4/deployments/0447057f-d7e7-47b0-a45e-3c33baedd315/predictions", json=payload_scoring, headers=header) output = json.loads(response_scoring.text) print(output) for key in output: ab = output[key] print(ab) for key in ab[0]: bc = ab[0][key] print(bc) roundedExpectancy = round(bc[0][0], 2) print(roundedExpectancy) form.abc = roundedExpectancy # this returns the response back to the front page return render_template('predictorForm.html', form=form)
def startApp(): form = PredictionForm() return render_template('predictorForm.html', form=form)
def make_prediction(request, competition=None): if not competition: competition = Competition.objects\ .get(pk=settings.CURRENT_COMPETITION_ID) competition = Competition.objects.get(pk=competition) has_password = request.user.has_usable_password() current_prediction = Prediction.objects\ .filter(competition=competition, user=request.user)\ .order_by('-created_date') current_prediction = current_prediction.count()\ and current_prediction[0] or None now = datetime.datetime.now() top_predictions = Prediction.objects\ .filter(competition=competition) if current_prediction: top_predictions = top_predictions\ .exclude(pk=current_prediction.pk) top_predictions = top_predictions[:3] if not competition.is_open(): error = "This competition is now closed" if request.method == "POST": if has_password: form = PredictionForm(request.POST, request.FILES, default_table=current_prediction) else: form = PredictionPasswordForm(request.POST, request.FILES, default_table=current_prediction) if form.is_valid(): this_year = datetime.datetime(settings.CURRENT_SEASON, 1, 1) prediction = form.save() saving = request.POST.get('save', '') prediction_obj = Prediction.objects.get_or_create( user=request.user, name=request.user.email, competition=competition)[0] prediction_obj.teams.clear() for t_id in prediction: prediction_obj.teams.add(Team.objects.get(pk=t_id)) prediction_obj.edited_date = now prediction_obj.save() score = prediction_obj.calculateScore(force=True) goaldiff = prediction_obj.calculateGoalDiff(force=True) position = prediction_obj.calculatePosition() prediction_obj.position = position if not has_password: request.user.set_password(form.cleaned_data['password1']) request.user.save() if saving: transaction.commit() return redirect( reverse('logged_in') + '#comp-%s' % competition.pk) else: transaction.rollback() else: if has_password: form = PredictionForm(default_table=current_prediction) else: form = PredictionPasswordForm(default_table=current_prediction) return locals()