forked from openai/openai-quickstart-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
27 lines (20 loc) · 945 Bytes
/
app.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
import os
import openai
from flask import Flask, redirect, render_template, request, url_for
app = Flask(__name__)
openai.api_key = os.getenv("OPENAI_API_KEY")
@app.route("/", methods=("GET", "POST"))
def index():
if request.method == "POST":
episode = request.form["episodio"]
response = openai.Completion.create(
model="text-davinci-003",
prompt=generate_prompt(episode),
temperature=0.6,
max_tokens=2500
)
return redirect(url_for("index", result=response.choices[0].text))
result = request.args.get("result")
return render_template("index.html", result=result)
def generate_prompt(episode):
return f"Summarize the episode '{episode}' of the podcast 'Mi Mejor Versión con Isa Garcia' in Spanish. Then list the key sections of the podcast. Each section should include the minute and second that they start. List each section in a newline."