-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPP.py
More file actions
67 lines (36 loc) · 1.15 KB
/
Copy pathAPP.py
File metadata and controls
67 lines (36 loc) · 1.15 KB
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
59
60
61
62
63
#!/usr/bin/env python
# coding: utf-8
# In[1]:
pip install flask
# In[1]:
pip install openai
# In[ ]:
from flask import Flask, render_template, request
import json,time,requests
app = Flask(__name__)
@app.route("/",methods=["GET","POST"])
def index():
if request.method == "POST":
q = request.form.get("question")
body = json.dumps(
{
"version" :"db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf",
"input":{
"prompt":q
}
}
)
headers = {
"Authorization":"Token r8_ANNl3TTCJ1uo2RCD9XWiia7hOPXQQEY18KOKP",
"Content-Type":"application/json"
}
output = requests.post("https://api.replicate.com/v1/predictions",data=body,headers=headers)
time.sleep(10)
get_url = output.json()["urls"]["get"]
get_result = requests.post(get_url,headers=headers).json()['output']
return(render_template("index2.html",result=get_result[0]))
else:
return(render_template("index2.html",result="waiting"))
if __name__=="__main__":
app.run()
# In[ ]: