def start_test_server(): pywebio.enable_debug() from flask import Flask, send_from_directory from pywebio.platform.flask import webio_view, run_event_loop from pywebio import STATIC_PATH import threading import logging app = Flask(__name__) app.add_url_rule('/io', 'webio_view', webio_view(target, cdn=False), methods=['GET', 'POST', 'OPTIONS']) app.add_url_rule('/io2', 'webio_view_async_target', webio_view(async_target, cdn=False), methods=['GET', 'POST', 'OPTIONS']) @app.route('/') @app.route('/<path:static_file>') def serve_static_file(static_file='index.html'): return send_from_directory(STATIC_PATH, static_file) threading.Thread(target=run_event_loop, daemon=True).start() logging.getLogger('werkzeug').setLevel(logging.WARNING) app.run(port=8080, host='127.0.0.1')
app = Flask(__name__) def predict(): with popup("Face Match Classifier"): put_text("Good to see you again") img = file_upload("Select a image:", accept="images/*") put_processbar('bar') for i in range(1, 11): set_processbar('bar', i / 10) time.sleep(0.1) content = img['content'] nparr = np.fromstring(content, np.uint8) img = cv2.imdecode(nparr, cv2.IMREAD_COLOR) pred = helper.main(img) put_text('Predicted Person is : ', pred) # put_markdown(pred) put_image(content) app.add_url_rule('/tool', 'webio_view', webio_view(predict), methods=['GET', 'POST', 'OPTIONS']) app.run(host='localhost', port=80)
Seller_Type = select('Are you a dealer or an individual', ['Dealer', 'Individual']) if (Seller_Type == 'Individual'): Seller_Type = 106 else: Seller_Type = 195 Transmission = select('Transmission Type', ['Manual Car', 'Automatic Car']) if (Transmission == 'Manual Car'): Transmission = 261 else: Transmission = 40 prediction = model.predict([[Present_Price, Kms_Driven2, Fuel_Type, Seller_Type, Transmission, Owner, Year]]) output = round(prediction[0], 2) if output < 0: put_text("Sorry You can't sell this Car") else: put_text('You can sell this Car at price:',output) app.add_url_rule('/tool', 'webio_view', webio_view(predict), methods=['GET', 'POST', 'OPTIONS']) #if __name__ == '__main__': #predict() app.run(host='localhost', port=80) #visit http://localhost/tool to open the PyWebIO application.
if q2 == "The value of the gradient at extrema of a function is always zero": c += 1 if q3 == "Decision trees are prone to be overfit": c += 1 if q4 == "Normalize the data -> PCA -> training": c += 1 if q5 == "Stop Word Removal": c += 1 if c > 3: put_markdown("""# you are passed""") if c <= 3: put_markdown("""# you are failed""") app.add_url_rule('/tool', 'webio_view', webio_view(main), methods=['GET', 'POST', 'OPTIONS']) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("-p", "--port", type=int, default=8080) args = parser.parse_args() start_server(main, port=args.port)
style(put_text("2. Federal in form and unitary in spirit"),"color:SandyBrown") style(put_text("3. Rajasthan"),"color:SandyBrown") style(put_text("4. Madam Cama"),"color:SandyBrown") style(put_text("5. Surpluses"),"color:SandyBrown") style(put_text("6. Immune"),"color:SandyBrown") style(put_text("7. Parliament"),"color:SandyBrown") style(put_text("8. Banabhatta"),"color:SandyBrown") style(put_text("9. Indonesia"),"color:SandyBrown") style(put_text("10. Antartica\n\n\n"),"color:SandyBrown") if c>=5: style(put_text(name +", your score is: "+ str(c)),"color:MediumBlue") style(put_text("Result : Passed"),"color:Turquoise") else: style(put_text(name +", your score is: "+ str(c)),"color:Maroon") style(put_text("Result : failed"),"color:red") style(put_text("Thank you for your participation.."),"font-family:Cursive,sans-serif") app.add_url_rule('/','webio_view',webio_view(exam),methods=['GET','POST','OPTIONS']) if __name__=="__main__": port=os.environ.get('PORT',33507) app.run(host='localhost',port=port,debug=False)
BMI = weight / (height / 100)**2 print(f"YOUR BMI = {BMI}") top_status = [(16, 'Severely underweight'), (18.5, 'Underweight'), (25, 'Normal'), (30, 'Overweight'), (35, 'Moderately obese'), (float('inf'), 'Severely obese')] for top, status in top_status: if BMI <= top: put_text('Your BMI: %.1f. Category: %s' % (BMI, status)) break if __name__ == '__main__': # bmi() # webview.create_window('Hello world', pywebio.start_server(show_table, port=8888)) # webview.start() # app = Flask(__name__) # log = logging.getLogger('werkzeug') # log.setLevel(logging.ERROR) # log.disabled = True app.add_url_rule('/tool', 'webio_view', webio_view(layout_keys), methods=['GET', 'POST', 'OPTIONS']) # app.run(host='localhost', port=8089) webview.create_window('Flask example', app) webview.start()
defff_type = select('diferentiation scheme Type', ['forwrd', 'backwrd', 'central']) if (defff_type == 'forwrd'): defff_type = forwrd() elif (defff_type == 'backwrd'): defff_type = backwrd() elif (defff_type == 'central'): defff_type = central() bmi = deff_type app.add_url_rule('/tool', 'webio_view', webio_view(bmi), methods=['GET', 'POST', 'OPTIONS']) # need GET,POST and OPTIONS methods # app.run(host='localhost', port=500) if __name__ == '__main__': import argparse parser = argparse.ArgumentParser() parser.add_argument("-p", "--port", type=int, default=800) args = parser.parse_args() start_server(bmi, port=args.port)
if number < 0: put_text("Number must be greater than zero") number_getter() number_list.append(number) while number != 1: if number % 2 == 0: number = number // 2 number_list.append(number) else: number = 3 * number + 1 number_list.append(number) else: number_list.append(number) put_text( f"Seed number: {initial_number}.\nLargest number in sequence was {max(number_list)}\n" f"It took {len(number_list)-2} iterations to reach the number 1\n\n" ) put_html(make_graph(number_list)) number_getter() except ValueError: number_getter() app.add_url_rule('/number', 'webio_view', webio_view(number_getter), methods=['GET', 'POST', 'OPTIONS']) if __name__ == "__main__": app.run(host="127.0.0.1", port=8080, debug=True)
} IMG_SIZE = 224 MODEL_PATH = './models/resnet-model.h5' model = load_model(MODEL_PATH) def predict_img(): img_upload = file_upload(label='Upload image', multiple=False, accept='image/*', placeholder='Upload an image of pokemon', required=True) file_path = img_upload.get('filename') print(file_path) img = image.load_img(file_path, target_size=(IMG_SIZE, IMG_SIZE)) x = image.img_to_array(img) pred = model.predict(np.expand_dims(x, axis=0)) res = np.argmax(pred, axis=1) im = open(file_path, 'rb').read() put_image(im, width='400px', height='400px') put_text("This pokemon is", IMG_CATEGORIES.get(int(res))) app.add_url_rule('/tool', 'webio_view', webio_view(predict_img), methods=['GET', 'POST', 'OPTIONS']) app.run(host='localhost', port=80)
# 自己程序 def expand_line(compressed_line): refs = compressed_line.split(',') for i, ref in enumerate(refs): refs[i] = expand_ref(ref) return ','.join(refs) # 自己程序 def task_func(): set_env(title="Ref Expander") put_markdown('本页面可以将压缩位号(U5-U10)转换为未压缩的位号(U5,U6,U7,U8,U9,U10)。') str2process = textarea('输入压缩位号:', rows=15, placeholder='可多行,行内逗号分割。') lines = str2process.split('\n') for i, line in enumerate(lines): lines[i] = expand_line(line) expanded_lines = '\n'.join(lines) put_markdown('未压缩的位号为:') put_markdown(expanded_lines) # Flask+WebIO框架 app = Flask(__name__) # `task_func` is PyWebIO task function app.add_url_rule('/', 'webio_view', webio_view(task_func), methods=['GET', 'POST', 'OPTIONS']) # need GET,POST and OPTIONS methods
selected_index = int(selected_index) try: row = dataset2.iloc[selected_index] set_scope('BTV', -1, -1, 'clear') clear('BTV') put_markdown(r""" # How to reach""", lstrip=True, scope='BTV') t = row['how to reach'] t = t.strip() t = t.replace('-', '') put_text(t, scope='BTV') except Exception as ex: put_text(ex) app = Flask(__name__) # app.add_url_rule('/', 'webio_view', webio_view(choices), methods=['GET', 'POST', 'OPTIONS']) # app.run() app.add_url_rule('/tool', 'webio_view', webio_view(choices), methods=['GET', 'POST', 'OPTIONS']) # app.run(host='localhost', port=80) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("-p", "--port", type=int, default=8080) args = parser.parse_args() start_server(choices, port=args.port)
def sentiment_analysis(): text=input("enter text to know whether the tweet ie positive or negative or neutral: ",type='text') x=TextBlob(text) sentiment_polarity=x.sentiment.polarity #sentiment_polarity_output=[(0,["positive","negative","nuetral"])] if sentiment_polarity>0: put_text("The given tweet looks : positive") elif sentiment_polarity<0: put_text("The given tweet looks : negative") elif sentiment_polarity==0: put_text("The given tweet looks : neutral") app.add_url_rule('/predict','webio_view',webio_view(sentiment_analysis), methods=['GET','POST','OPTIONS']) #app.run(host='localhost',port=80) if __name__="__main__": parser