Skip to content

Instantly share code, notes, and snippets.

@bkocis
Created April 7, 2024 20:41
Show Gist options
  • Save bkocis/5e64854fa1bd99d0614bc03fdcfd5917 to your computer and use it in GitHub Desktop.
Save bkocis/5e64854fa1bd99d0614bc03fdcfd5917 to your computer and use it in GitHub Desktop.
model load time GPU memory [GB/6.7] answer time (prompt: “Write me a simple flask application in python” answer
deepseek-coder:1.3b-instruct-q2_K 11.74 1.6 14.72 Sure! Here's an example of how could be done with Flask (a micro web framework for Python). This is very basic; it serves as the backend server and doesn't handle any front-end logic. ```python from flask import Flask, render_template, request app = Flask(__name__) @app.route('/') def home(): return "Hello World!" # or whatever you want to display on the webpage itself (render template) if __name__ == '__main__': # Ensure this is top level code block before running app, hence use `run(debug=True/False)` accordingly. app.run(debug = True) # Debug mode on by default which automatically reloads the server whenever there're changes in source files to be reflected when developing and debugging purpose! It is turned off for production deployments, it helps us a lot during development phase with little overhead like network latency etc.. ``` You can run this file as python script or use command `python [filename].py`. Open your browser on localhost:5000/w (the root path) to see the application in action! There's also an alternative template engine called Jinja2, and it allows you more power over HTML rendering with tags like {{}} which can be used for passing variables from Python script into html file.
gemma:2b-instruct 24.01 2.6 17.42 ```python from flask import Flask, request app = Flask(__name__) @app.route("/") def home(): return "Hello, world!" if __name__ == "__main__": app.run() ``` **Explanation:** * The code imports the Flask library and creates an instance of the Flask object. * The `home()` function is defined as the main handler for the root route (`/`). It returns the text "Hello, world!". * The `if __name__ == "__main__"` block ensures that the script is only executed when the file is run directly, and not imported. * The `app.run()` method starts the Flask application. **Running the Application:** 1. Save the code in a file named `app.py`. 2. Open a terminal and navigate to the directory where the file is saved. 3. Run the following command: ``` python app.py ``` 4. Access the application in your browser by visiting: ``` http://localhost:5000/ ``` **Output:** ``` Hello, world! ``` **Output Explanation:** * The `home()` function returns the text "Hello, world!". * The request object (`request`) provides access to HTTP request information, such as the method, URL, and headers. * The `if __name__ == "__main__"` block ensures that the code is not executed as a module.
gemma:2b-instruct-q2_K 20.98 2.3 21.47 ```python import flask # Create a Flask app app = flask.Flask(__name__) # Define a route @app.route("/", methods=["GET"]) def index(): return "Hello World!" # Run the app if __name__ == "__main__": app.run() ``` **How it works:** 1. **Import the Flask module:** We import the Flask class from the Flask module. 2. **Create a Flask app:** We create an instance of the Flask class and pass the name of the app as a parameter. 3. **Define a route:** We define a route with the `@app.route` decorator and specify the HTTP method as "GET" and the URL as the empty string ("/"). 4. **Handle the request:** We handle the request and return a response. 5. **Run the app:** We call the `run` method to start the Flask app. **To use the application:** 1. Save the file and run the command: `python flask_app.py` 2. Open your browser and navigate to `localhost:5000`. **Output:** When you open the application in the browser, it should display the text: "Hello World!" **Note:** * You can modify the `index` function to return different HTML content. * You can use the `request` object to access the HTTP request details.
gemma:7b-instruct-q2_K 48.36 4.5 In 1 min write three lines ```python from flask import Flask app =^C
deepseek-coder:6.7b-instruct-q2_ 20.61 3.6 2min 08.58 Sure, here is a basic Flask app that responds with "Hello World!" on the root path ("/") and another message when an additional endpoint "/greet" is accessed. ```python from flask import Flask app = Flask(__name__) @app.route('/') def home(): return 'Hello, World!' @app.route('/greet') def greet(): return 'Greetings! How are you today?' if __name__ == "__main__": app.run(debug=True) ``` This is a very basic example and might not cover all your needs, but it gives you an idea of how to use Flask in Python. It defines two routes ("/" and "/greet") with their respective functions, and then starts the server on localhost at port 5000 if run from the command line with "python filename.py".
dolphincoder:15b-starcoder2-q2_K 53.55 3.8 In 2 min wrote 3 lines of code ```python from flask import Flask app = Flask(__name__)
deepseek-coder:33b-instruct-q2_K 1min 27.53 3.8 2 words generated in 2min…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment