-
Notifications
You must be signed in to change notification settings - Fork 1
/
ATS.py
117 lines (88 loc) · 3.12 KB
/
ATS.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import json
import nlpcloud
import requests
main_part = "api_ZzORHqQQAGyPQmRYrRkqcWfSqGkgSMpUKc"
token = "Bearer " + main_part
'''
def question_answering(question, context):
headers = {"Authorization": token}
API_URL = "https://api-inference.huggingface.co/models/deepset/roberta-base-squad2"
def query(payload):
data = json.dumps(payload)
response = requests.request("POST", API_URL, headers=headers, data=data)
return json.loads(response.content.decode("utf-8"))
data = query(
{
"inputs": {
"question": question,
"context": context,
}
}
)
return data['answer']
'''
def at_sum(context):
client = nlpcloud.Client("bart-large-cnn", "dadbdbaebb34b57763094752c9049a932a725028")
result = client.summarization(context)
return result['summary_text']
def translate_text_hi_en(input_text):
API_URL = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-hi-en"
headers = {"Authorization": token}
def query(payload):
data = json.dumps(payload)
response = requests.request("POST", API_URL, headers=headers, data=data)
return json.loads(response.content.decode("utf-8"))
data = query(
{
"inputs": input_text,
}
)
return data[0]['translation_text']
def translate_text_en_hi(input_text):
API_URL = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-hi"
headers = {"Authorization": token}
def query(payload):
data = json.dumps(payload)
response = requests.request("POST", API_URL, headers=headers, data=data)
return json.loads(response.content.decode("utf-8"))
data = query(
{
"inputs": input_text,
}
)
return data[0]['translation_text']
def title_gen(context):
API_URL = "https://api-inference.huggingface.co/models/Callidior/bert2bert-base-arxiv-titlegen"
headers = {"Authorization": token}
def query(payload):
data = json.dumps(payload)
response = requests.request("POST", API_URL, headers=headers, data=data)
return json.loads(response.content.decode("utf-8"))
data = query(
{
"inputs": context,
}
)
return data[0]['summary_text']
def question_answering(question, context):
client = nlpcloud.Client("roberta-base-squad2", "dadbdbaebb34b57763094752c9049a932a725028")
print("fine 1 -----------------")
print(context )
print("----------------------------")
print(question , "--------------------")
result = client.question(context, question)
print("fine 2 ---------------")
return result['answer']
def at_sum(context):
headers = {"Authorization": token}
API_URL = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn"
def query(payload):
data = json.dumps(payload)
response = requests.request("POST", API_URL, headers=headers, data=data)
return json.loads(response.content.decode("utf-8"))
data = query(
{
"inputs": context,
}
)
return data[0]['summary_text']