-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp-old.py
46 lines (36 loc) · 1.16 KB
/
app-old.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
from flask import Flask, render_template, request
import openai
import os
app = Flask(__name__)
openai.api_key = "YOUR-API-KEY"
@app.route("/", methods=["GET"])
def index():
return render_template("index.html")
@app.route("/convert", methods=["POST"])
def translate():
if request.method == "POST":
source_language = request.form.get("source")
target_language = request.form.get("target")
code = request.form.get("code")
prompt = f"Translate this function from {source_language} into {target_language} ### {source_language} \n\n {code} \n\n ### {target_language}"
response = openai.Completion.create(
model="text-davinci-003",
prompt= prompt,
temperature=0,
max_tokens=1050,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
stop=["###"]
)
output = response.choices[0].text
return render_template("translate.html", output=output)
if __name__ == '__main__':
app.run()
# factorial recursion function
# def factorial(n):
# if n == 0:
# return 1
# else:
# return n * factorial(n-1)
#