Spaces:
Sleeping
Sleeping
GuysRGithub commited on
Commit ·
a4cc6d9
1
Parent(s): 2d97fd7
Update
Browse files123456789101112136 unmodified lines202122232425262 unmodified lines293031323334353637383961 unmodified lines1011021031041051061 unmodified line108109110111112from flask import Flask, requestimport requestsimport osfrom transformers import AutoModelForSeq2SeqLMfrom transformers import AutoTokenizerimport subprocesstokenizer = AutoTokenizer.from_pretrained("facebook/bart-base")model = AutoModelForSeq2SeqLM.from_pretrained("GuysTrans/bart-base-finetuned-xsum")def generate_summary(question, model):6 unmodified lines)input_ids = inputs.input_ids.to(model.device)attention_mask = inputs.attention_mask.to(model.device)outputs = model.generate(input_ids, attention_mask=attention_mask, max_new_tokens=512)output_str = tokenizer.batch_decode(outputs, skip_special_tokens=True)return outputs, output_str2 unmodified linesFB_API_URL = 'https://graph.facebook.com/v2.6/me/messages'VERIFY_TOKEN = '5rApTs/BRm6jtiwApOpIdjBHe73ifm6mNGZOsYkwwAw='PAGE_ACCESS_TOKEN = os.environ['PAGE_ACCESS_TOKEN'] # paste your page access token here>"def get_bot_response(message):return generate_summary(message, model)[1][0]def verify_webhook(req):61 unmodified linesreturn response.json()@app.route("/webhook/chat", methods=['POST'])def chat():payload = request.json1 unmodified lineresponse = get_bot_response(message)return {"message": response}subprocess.Popen(["autossh", "-M", "0" ,"-o", "StrictHostKeyChecking=no", "-i", "id_rsa", "-R", "guysmedchatt:80:localhost:7860", "serveo.net"])# subprocess.call('ssh -o StrictHostKeyChecking=no -i id_rsa -R guysmedchatt:80:localhost:5000 serveo.net', shell=True)123456789101112131415161718192021222324252627282930316 unmodified lines38394041424344452 unmodified lines48495051525354555657585961 unmodified lines1211221231241251261271 unmodified line129130131132133134135136137138139140141142143144145146147148149150151from flask import Flask, requestimport requestsimport osimport refrom transformers import AutoModelForSeq2SeqLMfrom transformers import AutoTokenizerimport subprocesstokenizer = AutoTokenizer.from_pretrained("facebook/bart-base")model = AutoModelForSeq2SeqLM.from_pretrained("GuysTrans/bart-base-finetuned-xsum")map_words = {"Hello and Welcome to 'Ask A Doctor' service": "","Hello,": "","Hi,": "","Hello": "","Hi": ""}word_remove_sentence = ["hello","hi","regards","dr.","physician",]def generate_summary(question, model):6 unmodified lines)input_ids = inputs.input_ids.to(model.device)attention_mask = inputs.attention_mask.to(model.device)outputs = model.generate(input_ids, attention_mask=attention_mask, max_new_tokens=512)output_str = tokenizer.batch_decode(outputs, skip_special_tokens=True)return outputs, output_str2 unmodified linesFB_API_URL = 'https://graph.facebook.com/v2.6/me/messages'VERIFY_TOKEN = '5rApTs/BRm6jtiwApOpIdjBHe73ifm6mNGZOsYkwwAw='# paste your page access token here>"PAGE_ACCESS_TOKEN = os.environ['PAGE_ACCESS_TOKEN']def get_bot_response(message):return post_process(generate_summary(message, model)[1][0])def verify_webhook(req):61 unmodified linesreturn response.json()@app.route("/webhook/chat", methods=['POST'])def chat():payload = request.json1 unmodified lineresponse = get_bot_response(message)return {"message": response}def post_process(output):lines = output.split("\n")for line in lines:for word in word_remove_sentence:if word in line.lower():lines.remove(line)breakoutput = "\n".join(lines)for item in map_words.keys():output = re.sub(item, map_words[item], output, re.I)return outputsubprocess.Popen(["autossh", "-M", "0", "-o", "StrictHostKeyChecking=no","-i", "id_rsa", "-R", "guysmedchatt:80:localhost:7860", "serveo.net"])# subprocess.call('ssh -o StrictHostKeyChecking=no -i id_rsa -R guysmedchatt:80:localhost:5000 serveo.net', shell=True)
app.py+44-5