Spaces:
Sleeping
Sleeping
prlabs2023
commited on
Commit
•
2eabb0b
1
Parent(s):
eca8f34
Update app.py
Browse files
app.py
CHANGED
@@ -29,6 +29,10 @@ from fastapi import Form
|
|
29 |
# from transformers import TFAutoModelForSequenceClassification
|
30 |
# from transformers import AutoTokenizer, AutoConfig
|
31 |
import numpy as np
|
|
|
|
|
|
|
|
|
32 |
|
33 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM,pipeline
|
34 |
|
@@ -47,7 +51,7 @@ def paraphrase(
|
|
47 |
diversity_penalty=3.0,
|
48 |
no_repeat_ngram_size=2,
|
49 |
temperature=0.7,
|
50 |
-
max_length=
|
51 |
):
|
52 |
input_ids = tokenizer(
|
53 |
f'paraphrase: {question}',
|
@@ -75,6 +79,15 @@ class Query(BaseModel):
|
|
75 |
|
76 |
|
77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
from fastapi import FastAPI, Request, Depends, UploadFile, File
|
79 |
from fastapi.exceptions import HTTPException
|
80 |
from fastapi.middleware.cors import CORSMiddleware
|
@@ -123,11 +136,39 @@ async def get_answer(q: Query ):
|
|
123 |
return x[0]
|
124 |
|
125 |
|
|
|
|
|
|
|
126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
|
128 |
-
|
129 |
-
|
130 |
-
|
|
|
|
|
131 |
|
132 |
|
133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
# from transformers import TFAutoModelForSequenceClassification
|
30 |
# from transformers import AutoTokenizer, AutoConfig
|
31 |
import numpy as np
|
32 |
+
import threading
|
33 |
+
import random
|
34 |
+
import string
|
35 |
+
import time
|
36 |
|
37 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM,pipeline
|
38 |
|
|
|
51 |
diversity_penalty=3.0,
|
52 |
no_repeat_ngram_size=2,
|
53 |
temperature=0.7,
|
54 |
+
max_length=10000
|
55 |
):
|
56 |
input_ids = tokenizer(
|
57 |
f'paraphrase: {question}',
|
|
|
79 |
|
80 |
|
81 |
|
82 |
+
|
83 |
+
class Query2(BaseModel):
|
84 |
+
text: str
|
85 |
+
host:str
|
86 |
+
|
87 |
+
|
88 |
+
|
89 |
+
|
90 |
+
|
91 |
from fastapi import FastAPI, Request, Depends, UploadFile, File
|
92 |
from fastapi.exceptions import HTTPException
|
93 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
136 |
return x[0]
|
137 |
|
138 |
|
139 |
+
|
140 |
+
@app.post("/large")
|
141 |
+
async def get_answer2(q: Query2 ):
|
142 |
|
143 |
+
text = q.text
|
144 |
+
host= q.host
|
145 |
+
|
146 |
+
N = 20
|
147 |
+
res = ''.join(random.choices(string.ascii_uppercase +
|
148 |
+
string.digits, k=N))
|
149 |
+
res= res+ str(time.time())
|
150 |
+
|
151 |
+
id= res
|
152 |
|
153 |
+
t = threading.Thread(target=do_ML, args=(id,text,host))
|
154 |
+
t.start()
|
155 |
+
|
156 |
+
return JSONResponse({"id":id})
|
157 |
+
|
158 |
|
159 |
|
160 |
|
161 |
+
|
162 |
+
def do_ML(id:str,text:str,host:str):
|
163 |
+
try:
|
164 |
+
x= paraphrase(text)
|
165 |
+
result=x[0]
|
166 |
+
data={"id":id,"result":result}
|
167 |
+
x=requests.post(host,data= data)
|
168 |
+
print(x.text)
|
169 |
+
|
170 |
+
|
171 |
+
except:
|
172 |
+
print("Error occured id="+id)
|
173 |
+
|
174 |
+
|