-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
36 lines (28 loc) · 1.11 KB
/
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
28
29
30
31
32
33
34
35
36
from flask import Flask, render_template, request
import os
import openai
app = Flask(__name__, template_folder='templates')
with open('/Users/aryanarora/Desktop/Projs/myproject/docs/openaiAPI.txt') as f:
openai.api_key = f.read().strip()
@app.route('/')
def home():
return render_template('home.html')
@app.route('/itinerary', methods=['POST'])
def itinerary():
location = request.form['location']
start_date = request.form['start_date']
end_date = request.form['end_date']
location = location.title()
prompt = f"Input: Itinerary for {location} from: {start_date} to {end_date}\n\nOutput(give day to day and hour by hour itinerary): \n"
response = openai.Completion.create(
model="text-davinci-003",
prompt=prompt,
temperature=0.9,
max_tokens=300,
top_p=1,
frequency_penalty=0,
presence_penalty=0.6,
stop=[" Human:", " AI:"]
)
itinerary = response.choices[0].text.strip().replace("\n", "<br>")
return render_template('after_button.html', itinerary=itinerary, location=location, start_date=start_date, end_date=end_date)