KvrParaskevi commited on
Commit
a8f32b2
1 Parent(s): b928f2f

Create request.py

Browse files
Files changed (1) hide show
  1. request.py +32 -0
request.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import json
3
+ import os
4
+
5
+ API_URL = "https://kp4xdy196cw81uf3.us-east-1.aws.endpoints.huggingface.cloud"
6
+ token = os.getenv('HUGGINGFACEHUB_API_TOKEN')
7
+ headers = {
8
+ "Accept" : "application/json",
9
+ "Authorization": "Bearer " + token,
10
+ "Content-Type": "application/json"
11
+ }
12
+
13
+ def query(payload):
14
+ response = requests.post(API_URL, headers=headers, json=payload)
15
+ return response.json()
16
+
17
+ def generate_response(text):
18
+ input = {
19
+ "inputs": text,
20
+ "parameters": {
21
+ "max_new_tokens" : 128,
22
+ "top_k": 10,
23
+ "top_p": 0.95,
24
+ "typical_p": 0.95,
25
+ "temperature": 0.01,
26
+ "repetition_penalty": 1.03,
27
+ "stop" : ["/nHuman:", "/nUser:", "<end of message>\n"]
28
+ }
29
+ }
30
+
31
+ output = query(input)
32
+ return output[0]["generated_text"]