-
Notifications
You must be signed in to change notification settings - Fork 1
/
storylib.py
58 lines (32 loc) · 1.12 KB
/
storylib.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
import requests
import json
import re
def getstorypics(url, sentence):
# url = "http://3973-34-124-230-90.ngrok.io/testgen"
payload = json.dumps({"sentence": sentence })
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
js = json.loads(response.text)
return js['imurls']
def getstory(url, sentence):
# url = "http://49b5-35-223-164-204.ngrok.io/getstory"
payload = json.dumps({"sentence": sentence})
sentence = re.sub('\s+(a|an|and|the)(\s+)', '\2', sentence)
wordlist = sentence.split()
payload = json.dumps({
"words": wordlist
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
js = json.loads(response.text)
surl = js['surl']
story = js['story']
surl = surl.replace("https://","")
print (surl)
return surl, story