Spaces:
Runtime error
Runtime error
Commit ·
f2d5f3c
1
Parent(s): 1df4f0c
switch back to old chatbot
Browse files
main.py
CHANGED
|
@@ -5,11 +5,11 @@ Based on: https://huggingface.co/docs/hub/spaces-sdks-docker-first-demo
|
|
| 5 |
|
| 6 |
from fastapi import FastAPI, Request
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
|
| 11 |
-
import gpt4free
|
| 12 |
-
from gpt4free import Provider, forefront
|
| 13 |
|
| 14 |
|
| 15 |
token_size_limit = None
|
|
@@ -17,8 +17,8 @@ token_size_limit = None
|
|
| 17 |
# FROM: https://huggingface.co/facebook/blenderbot-400M-distill?text=Hey+my+name+is+Thomas%21+How+are+you%3F
|
| 18 |
|
| 19 |
# LAST USED
|
| 20 |
-
|
| 21 |
-
|
| 22 |
|
| 23 |
# tokenizer = AutoTokenizer.from_pretrained("facebook/blenderbot-1B-distill")
|
| 24 |
# model = AutoModelForSeq2SeqLM.from_pretrained("facebook/blenderbot-1B-distill")
|
|
@@ -49,18 +49,18 @@ async def Reply(req: Request):
|
|
| 49 |
print(f'MSG: {msg}')
|
| 50 |
|
| 51 |
# Hugging face
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
|
| 61 |
# gpt4free
|
| 62 |
# usage theb
|
| 63 |
-
reply = gpt4free.Completion.create(Provider.Theb, prompt=msg)
|
| 64 |
|
| 65 |
print(f'REPLY: {reply}')
|
| 66 |
return {'reply': reply}
|
|
|
|
| 5 |
|
| 6 |
from fastapi import FastAPI, Request
|
| 7 |
|
| 8 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 9 |
+
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
| 10 |
|
| 11 |
+
# import gpt4free
|
| 12 |
+
# from gpt4free import Provider, forefront
|
| 13 |
|
| 14 |
|
| 15 |
token_size_limit = None
|
|
|
|
| 17 |
# FROM: https://huggingface.co/facebook/blenderbot-400M-distill?text=Hey+my+name+is+Thomas%21+How+are+you%3F
|
| 18 |
|
| 19 |
# LAST USED
|
| 20 |
+
tokenizer = AutoTokenizer.from_pretrained("facebook/blenderbot-400M-distill")
|
| 21 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("facebook/blenderbot-400M-distill")
|
| 22 |
|
| 23 |
# tokenizer = AutoTokenizer.from_pretrained("facebook/blenderbot-1B-distill")
|
| 24 |
# model = AutoModelForSeq2SeqLM.from_pretrained("facebook/blenderbot-1B-distill")
|
|
|
|
| 49 |
print(f'MSG: {msg}')
|
| 50 |
|
| 51 |
# Hugging face
|
| 52 |
+
input_ids = tokenizer(msg, return_tensors='pt').input_ids # .to('cuda')
|
| 53 |
+
output = model.generate(
|
| 54 |
+
input_ids[:, -token_size_limit:],
|
| 55 |
+
do_sample=True,
|
| 56 |
+
temperature=request.get('temperature', 0.9),
|
| 57 |
+
max_length=request.get('max_length', 100),
|
| 58 |
+
)
|
| 59 |
+
reply = tokenizer.batch_decode(output)[0]
|
| 60 |
|
| 61 |
# gpt4free
|
| 62 |
# usage theb
|
| 63 |
+
# reply = gpt4free.Completion.create(Provider.Theb, prompt=msg)
|
| 64 |
|
| 65 |
print(f'REPLY: {reply}')
|
| 66 |
return {'reply': reply}
|