<commit_before>from flask import Flask
app = Flask(__name__)


@app.route("/")
def home():
    return "Hello World!"<commit_msg>Add API to set leds color<commit_after>from flask import Flask, request
import pigpio
app = Flask(__name__)

#rgb 22, 27, 17
#base teal 40 97 15

GPIO_RED = 22
GPIO_GREEN = 27
GPIO_BLUE = 17

def to_PWM_dutycycle(string):
    try:
        i = int(string)
        if i < 0:
            i = 0
        elif i > 255:
            i = 255
        return i
    except ValueError:
        return 0

@app.route("/")
def home():
    return "Hello World!"

@app.route("/color")
def set_color():
    args = request.args.to_dict()
    r = to_PWM_dutycycle(args['r'])
    g = to_PWM_dutycycle(args['g'])
    b = to_PWM_dutycycle(args['b'])
    pi = pigpio.pi()
    pi.set_PWM_dutycycle(GPIO_RED, r)
    pi.set_PWM_dutycycle(GPIO_GREEN, g)
    pi.set_PWM_dutycycle(GPIO_BLUE, b)
    return str(r) + ' ' + str(g) + ' ' + str(b)

if __name__ == "__main__":
    #app.run(debug=True)
    app.run(host='0.0.0.0', port=8080, debug=True)

{'fraction_non_alphanumeric': 0.14272030651340997, 'fraction_numerical': 0.033524904214559385, 'mean_word_length': 2.856088560885609, 'pattern_counts': {'":': 1, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2577055', 'n_tokens_mistral': 443, 'n_tokens_neox': 406, 'n_words': 97}