Spaces:
Runtime error
Runtime error
Yash Sachdeva
commited on
Commit
·
d248ced
1
Parent(s):
70864b6
gpt2
Browse files- question_paper.py +8 -4
question_paper.py
CHANGED
@@ -1,10 +1,14 @@
|
|
1 |
-
from transformers import pipeline
|
|
|
|
|
|
|
2 |
from fastapi import FastAPI
|
3 |
from fastapi.middleware.cors import CORSMiddleware
|
4 |
from fastapi.encoders import jsonable_encoder
|
5 |
from fastapi.responses import JSONResponse
|
6 |
|
7 |
-
|
|
|
8 |
|
9 |
app = FastAPI()
|
10 |
|
@@ -30,9 +34,9 @@ def llama(input):
|
|
30 |
|
31 |
# tresponse = TOKENIZER.decode(tokens[0], skip_special_tokens=False)
|
32 |
# print(tresponse)
|
33 |
-
|
34 |
text = ""
|
35 |
-
for o in
|
36 |
text = text + ' ' + o["generated_text"]
|
37 |
response_message = {"message": text}
|
38 |
json_response = jsonable_encoder(response_message)
|
|
|
1 |
+
from transformers import pipeline, set_seed
|
2 |
+
generator = pipeline('text-generation', model='gpt2')
|
3 |
+
set_seed(40)
|
4 |
+
|
5 |
from fastapi import FastAPI
|
6 |
from fastapi.middleware.cors import CORSMiddleware
|
7 |
from fastapi.encoders import jsonable_encoder
|
8 |
from fastapi.responses import JSONResponse
|
9 |
|
10 |
+
|
11 |
+
tokenizer.pad_token_id = tokenizer.eos_token_id
|
12 |
|
13 |
app = FastAPI()
|
14 |
|
|
|
34 |
|
35 |
# tresponse = TOKENIZER.decode(tokens[0], skip_special_tokens=False)
|
36 |
# print(tresponse)
|
37 |
+
outputs = generator(input, max_length=100, num_return_sequences=5)
|
38 |
text = ""
|
39 |
+
for o in outputs:
|
40 |
text = text + ' ' + o["generated_text"]
|
41 |
response_message = {"message": text}
|
42 |
json_response = jsonable_encoder(response_message)
|