CoolFace
Apppublic

antonovmaxim/text-generation-webui-space

sourceHugging Facemitupdated 3y agoView on Hugging Face
12likes
api-example.py45 linesDownload Raw Back to root
1import requests2 3# For local streaming, the websockets are hosted without ssl - http://4HOST = 'localhost:5000'5URI = f'http://{HOST}/api/v1/generate'6 7# For reverse-proxied streaming, the remote will likely host with ssl - https://8# URI = 'https://your-uri-here.trycloudflare.com/api/v1/generate'9 10 11def run(prompt):12    request = {13        'prompt': prompt,14        'max_new_tokens': 250,15        'do_sample': True,16        'temperature': 1.3,17        'top_p': 0.1,18        'typical_p': 1,19        'repetition_penalty': 1.18,20        'top_k': 40,21        'min_length': 0,22        'no_repeat_ngram_size': 0,23        'num_beams': 1,24        'penalty_alpha': 0,25        'length_penalty': 1,26        'early_stopping': False,27        'seed': -1,28        'add_bos_token': True,29        'truncation_length': 2048,30        'ban_eos_token': False,31        'skip_special_tokens': True,32        'stopping_strings': []33    }34 35    response = requests.post(URI, json=request)36 37    if response.status_code == 200:38        result = response.json()['results'][0]['text']39        print(prompt + result)40 41 42if __name__ == '__main__':43    prompt = "In order to make homemade bread, follow these steps:\n1)"44    run(prompt)45