File size: 700 Bytes
5444ef5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import requests
import time 
from transformers import pipeline
import os

HF_AUTH_TOKEN = os.getenv('HF_AUTH_TOKEN')
headers = {"Authorization": f"Bearer {HF_AUTH_TOKEN}"}

def query(text, url, params=None):
	data = {"inputs": text, "parameters": params}
	while True:
		response = requests.post(url, headers=headers, json=data)
		if 'error' not in response.json():
			output = response.json()[0]["generated_text"]
			return output
		else:
			print(response.json())
			time.sleep(15)
			print('Sending request again', flush=True)


def pipe():
    pipe = pipeline("text2text-generation", model="boun-tabi-LMG/TURNA", tokenizer="boun-tabi-LMG/TURNA", temperature=0.7, repetition_penalty=0.5, top_p=0.9)