Skip to content

Instantly share code, notes, and snippets.

@basesd
Created June 12, 2023 00:14
Show Gist options
  • Select an option

  • Save basesd/3743f45a17fd9ae8d0fca32da22e332d to your computer and use it in GitHub Desktop.

Select an option

Save basesd/3743f45a17fd9ae8d0fca32da22e332d to your computer and use it in GitHub Desktop.
# from flask import Flask, request, render_template
In [2]:
app = Flask(__name__)
In [ ]:
@app.route('/')
def home():
return render_template('index.html')
In [ ]:
@app.route('/search', methods=['POST'])
def search():
query = request.form.get('query')
# TODO: Use ChatGPT, Google Places, and Yelp APIs to process the query
return 'Results for: ' + query
In [ ]:
!pip install requests
In [ ]:
import requests
In [ ]:
@app.route('/search', methods=['POST'])
def search():
query = request.form.get('query')
# Send the query to the ChatGPT API
chatgpt_url = 'https://api.openai.com/v1/engines/davinci-codex/completions'
chatgpt_headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer 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',
}
chatgpt_data = {
'prompt': query,
'max_tokens': 60,
}
response = requests.post(chatgpt_url, headers=chatgpt_headers, json=chatgpt_data)
chatgpt_response = response.json()
# TODO: Extract the relevant information from the ChatGPT response
# Send a request to the Google Places API
places_url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
places_params = {
'query': query,
'key': 'AIzaSyCfmQXjAzTsj1dUj2d1Sorg8JR5SerPPYU',
}
response = requests.get(places_url, params=places_params)
places_response = response.json()
# TODO: Extract the relevant information from the Google Places response
return 'Results for: ' + query
In [ ]:
@app.route('/new-search', methods=['POST'], endpoint='new_search')
def search():
query = request.form.get('query')
# Send the query to the ChatGPT API
chatgpt_url = 'https://api.openai.com/v1/engines/davinci-codex/completions'
chatgpt_headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer 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',
}
chatgpt_data = {
'prompt': query,
'max_tokens': 60,
}
response = requests.post(chatgpt_url, headers=chatgpt_headers, json=chatgpt_data)
chatgpt_response = response.json()
# TODO: Extract the relevant information from the ChatGPT response
# Send a request to the Google Places API
places_url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
places_params = {
'query': query,
'key': 'AIzaSyCfmQXjAzTsj1dUj2d1Sorg8JR5SerPPYU',
}
response = requests.get(places_url, params=places_params)
places_response = response.json()
# TODO: Extract the relevant information from the Google Places response
return 'Results for: ' + query
In [ ]:
data = response.json()
name = data['name']
rating = data['rating']
In [ ]:
response = requests.get(url, headers=headers_or_params)
In [ ]:
url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
headers_or_params = {
'query': 'coffee shop',
'key': 'AIzaSyCfmQXjAzTsj1dUj2d1Sorg8JR5SerPPYU',
}
In [ ]:
requests.get(url, headers=headers_or_params)
In [ ]:
data = response.json()
In [ ]:
response = requests.get(url, headers=headers_or_params)
In [ ]:
data = response.json()
In [ ]:
response = requests.get(url, headers=headers_or_params)
data = response.json()
In [ ]:
print(data)
In [ ]:
places_params = {
'query': query,
'key': 'AIzaSyAuHb4dRygN_UdzmqLPmdHd54UwshhbjgY',
}
response = requests.get(places_url, params=places_params)
In [ ]:
query = 'coffee shop'
places_params = {
'query': query,
'key': 'AIzaSyAuHb4dRygN_UdzmqLPmdHd54UwshhbjgY',
}
In [ ]:
data = response.json()
In [ ]:
print(data)
In [ ]:
@app.route('/new-search', methods=['POST'], endpoint='new_search')
def search():
query = request.form.get('query')
# Send the query to the ChatGPT API
chatgpt_url = 'https://api.openai.com/v1/engines/davinci-codex/completions'
chatgpt_headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer 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',
}
chatgpt_data = {
'prompt': query,
'max_tokens': 60,
}
response = requests.post(chatgpt_url, headers=chatgpt_headers, json=chatgpt_data)
chatgpt_response = response.json()
# TODO: Extract the relevant information from the ChatGPT response
# Send a request to the Google Places API
places_url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
places_params = {
'query': query,
'key': 'AIzaSyAuHb4dRygN_UdzmqLPmdHd54UwshhbjgY',
}
response = requests.get(places_url, params=places_params)
places_response = response.json()
# TODO: Extract the relevant information from the Google Places response
return 'Results for: ' + query
In [ ]:
@app.route('/new-search', methods=['POST'], endpoint='new_search_result')
def search():
query = request.form.get('query')
# Send the query to the ChatGPT API
chatgpt_url = 'https://api.openai.com/v1/engines/davinci-codex/completions'
chatgpt_headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer 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',
}
chatgpt_data = {
'prompt': query,
'max_tokens': 60,
}
response = requests.post(chatgpt_url, headers=chatgpt_headers, json=chatgpt_data)
chatgpt_response = response.json()
# TODO: Extract the relevant information from the ChatGPT response
# Send a request to the Google Places API
places_url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
places_params = {
'query': query,
'key': 'AIzaSyAuHb4dRygN_UdzmqLPmdHd54UwshhbjgY',
}
response = requests.get(places_url, params=places_params)
places_response = response.json()
# TODO: Extract the relevant information from the Google Places response
return 'Results for: ' + query
In [ ]:
app.run()
In [ ]:
- your_app.py
- templates/
- index.html
In [ ]:
app.run()
In [1]:
from flask import Flask, request, render_template
import requests
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/new-search', methods=['POST'], endpoint='search')
def search():
query = request.form.get('query')
# Send the query to the ChatGPT API
chatgpt_url = 'https://api.openai.com/v1/engines/davinci-codex/completions'
chatgpt_headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer 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',
}
chatgpt_data = {
'prompt': query,
'max_tokens': 60,
}
response = requests.post(chatgpt_url, headers=chatgpt_headers, json=chatgpt_data)
chatgpt_response = response.json()
# TODO: Extract the relevant information from the ChatGPT response
# Send a request to the Google Places API
places_url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
places_params = {
'query': query,
'key': 'AIzaSyAuHb4dRygN_UdzmqLPmdHd54UwshhbjgY',
}
response = requests.get(places_url, params=places_params)
places_response = response.json()
# TODO: Extract the relevant information from the Google Places response
return 'Results for: ' + query
if __name__ == '__main__':
app.run()
* Serving Flask app "__main__" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [04/Jun/2023 23:04:12] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [04/Jun/2023 23:04:17] "POST /search2 HTTP/1.1" 404 -
127.0.0.1 - - [04/Jun/2023 23:04:18] "POST /search2 HTTP/1.1" 404 -
127.0.0.1 - - [04/Jun/2023 23:04:19] "POST /search2 HTTP/1.1" 404 -
127.0.0.1 - - [04/Jun/2023 23:04:19] "POST /search2 HTTP/1.1" 404 -
127.0.0.1 - - [04/Jun/2023 23:04:20] "POST /search2 HTTP/1.1" 404 -
In [ ]:
- your_app.py
- templates/
- index.html
In [ ]:
from flask import Flask, request, render_template
import requests
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/new-search', methods=['POST'], endpoint='search')
def search():
query = request.form.get('query')
# Send the query to the ChatGPT API
chatgpt_url = 'https://api.openai.com/v1/engines/davinci-codex/completions'
chatgpt_headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer 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',
}
chatgpt_data = {
'prompt': query,
'max_tokens': 60,
}
response = requests.post(chatgpt_url, headers=chatgpt_headers, json=chatgpt_data)
chatgpt_response = response.json()
# TODO: Extract the relevant information from the ChatGPT response
# Send a request to the Google Places API
places_url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
places_params = {
'query': query,
'key': 'AIzaSyAuHb4dRygN_UdzmqLPmdHd54UwshhbjgY',
}
response = requests.get(places_url, params=places_params)
places_response = response.json()
# TODO: Extract the relevant information from the Google Places response
return 'Results for: ' + query
if __name__ == '__main__':
app.run(debug=True)
In [ ]:
from flask import Flask, request, render_template
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/search', methods=['POST'])
def search():
query = request.form.get('query')
# TODO: Use ChatGPT, Google Places, and Yelp APIs to process the query
return 'Results for: ' + query
if __name__ == '__main__':
app.run()
In [ ]:
import os
print(os.getcwd())
In [ ]:
import os
os.mkdir('templates')
In [ ]:
with open('templates/index.html', 'w') as file:
file.write('<html><body><h1>Hello, World!</h1></body></html>')
In [ ]:
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
if __name__ == '__main__':
app.run()
In [ ]:
response = requests.get(url, headers=headers_or_params)
In [ ]:
app.run()
In [ ]:
- your_app.py
- templates/
- index.html
In [ ]:
response = requests.get(url, headers=headers_or_params)
In [ ]:
!pip install requests
In [ ]:
response = requests.get(url, headers=headers_or_params)
In [ ]:
!pip install requests
In [ ]:
import requests
url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
headers_or_params = {
'query': 'coffee shop',
'key': 'AIzaSyAuHb4dRygN_UdzmqLPmdHd54UwshhbjgY',
}
response = requests.get(url, headers=headers_or_params)
In [ ]:
response = requests.get(url, headers=headers_or_params)
data = response.json()
# Extract relevant information from the response
results = data['results']
for result in results:
name = result['name']
rating = result['rating']
# Do something with the extracted information
print(f"Name: {name}, Rating: {rating}")
In [ ]:
@app.route('/search', methods=['POST'])
def search():
query = request.form.get('query')
# Send a request to the Google Places API and extract relevant information
# ...
return render_template('results.html', query=query, results=results)
In [ ]:
<!DOCTYPE html>
<html>
<head>
<title>Search Results</title>
</head>
<body>
<h1>Results for: {{ query }}</h1>
<ul>
{% for result in results %}
<li>{{ result.name }} - Rating: {{ result.rating }}</li>
{% endfor %}
</ul>
</body>
</html>
In [ ]:
app.run()
In [ ]:
from flask import render_template
@app.route('/')
def index():
return render_template('index.html')
In [ ]:
@app.route('/')
def index():
return render_template('index.html')
In [ ]:
app.run()
In [ ]:
app.run(debug=True)
In [ ]:
app.run(debug=True)
In [ ]:
%tb
In [ ]:
app.run(debug=True)
In [ ]:
app.run()
In [ ]:
app.run()
In [ ]:
from flask import Flask, request, render_template
import requests
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/new-search', methods=['POST'], endpoint='search')
def search():
query = request.form.get('query')
# Send the query to the ChatGPT API
chatgpt_url = 'https://api.openai.com/v1/engines/davinci-codex/completions'
chatgpt_headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer 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',
}
chatgpt_data = {
'prompt': query,
'max_tokens': 60,
}
response = requests.post(chatgpt_url, headers=chatgpt_headers, json=chatgpt_data)
chatgpt_response = response.json()
# TODO: Extract the relevant information from the ChatGPT response
# Send a request to the Google Places API
places_url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
places_params = {
'query': query,
'key': 'AIzaSyAuHb4dRygN_UdzmqLPmdHd54UwshhbjgY',
}
response = requests.get(places_url, params=places_params)
places_response = response.json()
# TODO: Extract the relevant information from the Google Places response
return 'Results for: ' + query
if __name__ == '__main__':
app.run()
In [ ]:
from flask import Flask, request, render_template, jsonify
import requests
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/search', methods=['POST'])
def search():
query = request.form.get('query')
# Send the query to the ChatGPT API
chatgpt_url = 'https://api.openai.com/v1/engines/davinci-codex/completions'
chatgpt_headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer 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',
}
chatgpt_data = {
'prompt': query,
'max_tokens': 60,
}
response = requests.post(chatgpt_url, headers=chatgpt_headers, json=chatgpt_data)
chatgpt_response = response.json()
# Send a request to the Google Places API
places_url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
places_params = {
'query': query,
'key': 'AIzaSyAuHb4dRygN_UdzmqLPmdHd54UwshhbjgY',
}
response = requests.get(places_url, params=places_params)
places_response = response.json()
# Process the responses and extract relevant information
# TODO: Implement your logic here
# Create a response object with the extracted information
result = {
'query': query,
'chatgpt_response': chatgpt_response,
'places_response': places_response,
}
return jsonify(result)
if __name__ == '__main__':
app.run(debug=True)
In [ ]:
exit
In [ ]:
%tb
In [ ]:
app.run()
In [ ]:
app.run()
In [ ]:
app.run()
In [ ]:
from flask import jsonify
@app.route('/search', methods=['POST'])
def search():
# ...
return jsonify(result)
In [ ]:
@app.route('/search2', methods=['POST'])
def search2():
# ...
return jsonify(result)
In [ ]:
$.ajax({
url: "/search2",
// ...
});
In [ ]:
app.run()
In [ ]:
app.run()
In [ ]:
from flask import Flask, request, render_template, jsonify
import requests
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/search', methods=['POST'])
def search():
query = request.form.get('query')
# Send the query to the ChatGPT API
chatgpt_url = 'https://api.openai.com/v1/engines/davinci-codex/completions'
chatgpt_headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer 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',
}
chatgpt_data = {
'prompt': query,
'max_tokens': 60,
}
response = requests.post(chatgpt_url, headers=chatgpt_headers, json=chatgpt_data)
chatgpt_response = response.json()
# Send a request to the Google Places API
places_url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
places_params = {
'query': query,
'key': 'AIzaSyAuHb4dRygN_UdzmqLPmdHd54UwshhbjgY',
}
response = requests.get(places_url, params=places_params)
places_response = response.json()
# Process the responses and extract relevant information
# TODO: Implement your logic here
# Create a response object with the extracted information
result = {
'query': query,
'chatgpt_response': chatgpt_response,
'places_response': places_response,
}
return jsonify(result)
if __name__ == '__main__':
app.run(debug=True)
In [ ]:
%tb
In [ ]:
import nest_asyncio
from flask import Flask, request, render_template, jsonify
import requests
import threading
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/search', methods=['POST'])
def search():
query = request.form.get('query')
# Send the query to the ChatGPT API
chatgpt_url = 'https://api.openai.com/v1/engines/davinci-codex/completions'
chatgpt_headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer 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',
}
chatgpt_data = {
'prompt': query,
'max_tokens': 60,
}
response = requests.post(chatgpt_url, headers=chatgpt_headers, json=chatgpt_data)
chatgpt_response = response.json()
# Send a request to the Google Places API
places_url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
places_params = {
'query': query,
'key': 'AIzaSyAuHb4dRygN_UdzmqLPmdHd54UwshhbjgY',
}
response = requests.get(places_url, params=places_params)
places_response = response.json()
# Process the responses and extract relevant information
# TODO: Implement your logic here
# Create a response object with the extracted information
result = {
'query': query,
'chatgpt_response': chatgpt_response,
'places_response': places_response,
}
return jsonify(result)
def run_flask_app(app):
app.run(use_reloader=False)
nest_asyncio.apply()
threading.Thread(target=run_flask_app, args=(app,)).start()
In [ ]:
pip install nest_asyncio
In [ ]:
import nest_asyncio
from flask import Flask, request, render_template, jsonify
import requests
import threading
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/search', methods=['POST'])
def search():
query = request.form.get('query')
# Send the query to the ChatGPT API
chatgpt_url = 'https://api.openai.com/v1/engines/davinci-codex/completions'
chatgpt_headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer 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',
}
chatgpt_data = {
'prompt': query,
'max_tokens': 60,
}
response = requests.post(chatgpt_url, headers=chatgpt_headers, json=chatgpt_data)
chatgpt_response = response.json()
# Send a request to the Google Places API
places_url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
places_params = {
'query': query,
'key': 'AIzaSyAuHb4dRygN_UdzmqLPmdHd54UwshhbjgY',
}
response = requests.get(places_url, params=places_params)
places_response = response.json()
# Process the responses and extract relevant information
# TODO: Implement your logic here
# Create a response object with the extracted information
result = {
'query': query,
'chatgpt_response': chatgpt_response,
'places_response': places_response,
}
return jsonify(result)
def run_flask_app(app):
app.run(use_reloader=False)
nest_asyncio.apply()
threading.Thread(target=run_flask_app, args=(app,)).start()
In [ ]:
app.run()
In [3]:
from flask import Flask, request, render_template
import requests
app = Flask(__name__, template_folder='templates')
@app.route('/')
def home():
return render_template('index.html')
@app.route('/search', methods=['POST'])
def search():
query = request.form.get('query')
# Send the query to the ChatGPT API
chatgpt_url = 'https://api.openai.com/v1/engines/davinci-codex/completions'
chatgpt_headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer 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',
}
chatgpt_data = {
'prompt': query,
'max_tokens': 60,
}
response = requests.post(chatgpt_url, headers=chatgpt_headers, json=chatgpt_data)
chatgpt_response = response.json()
# Send a request to the Google Places API
places_url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
places_params = {
'query': query,
'key': 'AIzaSyAuHb4dRygN_UdzmqLPmdHd54UwshhbjgY',
}
response = requests.get(places_url, params=places_params)
places_response = response.json()
return 'Results for: ' + query
# Use this in Jupyter notebook
from IPython.display import display, HTML
import threading
def run_flask_app_in_background(app):
"""
Run a flask app in a background thread and open it in a browser window.
"""
def run_app():
app.run(port=5000)
def open_browser():
import webbrowser
webbrowser.open("http://localhost:5000/")
threading.Thread(target=run_app).start()
threading.Thread(target=open_browser).start()
run_flask_app_in_background(app)
* Serving Flask app "__main__" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
In [1]:
@app.route('/search', methods=['POST'])
def search():
query = request.form.get('query')
# Send the query to the ChatGPT API
chatgpt_url = 'https://api.openai.com/v1/engines/davinci-codex/completions'
chatgpt_headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer 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',
}
chatgpt_data = {
'prompt': query,
'max_tokens': 60,
}
response = requests.post(chatgpt_url, headers=chatgpt_headers, json=chatgpt_data)
chatgpt_response = response.json()
# Send a request to the Google Places API
places_url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
places_params = {
'query': query,
'key': 'your_api_key',
}
response = requests.get(places_url, params=places_params)
places_response = response.json()
# Process the responses and extract relevant information
# Example: Extract the relevant information from the ChatGPT response
chatgpt_results = chatgpt_response['choices'][0]['text']
# Example: Extract the relevant information from the Google Places response
places_results = places_response['results']
# Create a response object with the extracted information
result = {
'query': query,
'chatgpt_results': chatgpt_results,
'places_results': places_results,
}
return jsonify(result)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-78768452aa36> in <module>
----> 1 @app.route('/search', methods=['POST'])
2 def search():
3 query = request.form.get('query')
4
5 # Send the query to the ChatGPT API
NameError: name 'app' is not defined
In [2]:
from flask import Flask, request, render_template, jsonify
import requests
app = Flask(__name__, template_folder='templates')
@app.route('/')
def home():
return render_template('index.html')
@app.route('/search', methods=['POST'])
def search():
query = request.form.get('query')
# Send the query to the ChatGPT API
chatgpt_url = 'https://api.openai.com/v1/engines/davinci-codex/completions'
chatgpt_headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer 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',
}
chatgpt_data = {
'prompt': query,
'max_tokens': 60,
}
response = requests.post(chatgpt_url, headers=chatgpt_headers, json=chatgpt_data)
chatgpt_response = response.json()
# Send a request to the Google Places API
places_url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
places_params = {
'query': query,
'key': 'AIzaSyAuHb4dRygN_UdzmqLPmdHd54UwshhbjgY',
}
response = requests.get(places_url, params=places_params)
places_response = response.json()
# Process the responses and extract relevant information
# Example: Extract the relevant information from the ChatGPT response
chatgpt_results = chatgpt_response['choices'][0]['text']
# Example: Extract the relevant information from the Google Places response
places_results = places_response['results']
# Create a response object with the extracted information
result = {
'query': query,
'chatgpt_results': chatgpt_results,
'places_results': places_results,
}
return jsonify(result)
if __name__ == '__main__':
app.run(debug=True)
* Serving Flask app "__main__" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
An exception has occurred, use %tb to see the full traceback.
SystemExit: 1
/Users/carlos/opt/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py:3334: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
In [3]:
%tb
---------------------------------------------------------------------------
SystemExit Traceback (most recent call last)
<ipython-input-2-53295db196ca> in <module>
52
53 if __name__ == '__main__':
---> 54 app.run(debug=True)
~/opt/anaconda3/lib/python3.7/site-packages/flask/app.py in run(self, host, port, debug, load_dotenv, **options)
988
989 try:
--> 990 run_simple(host, port, self, **options)
991 finally:
992 # reset the first request information if the development server
~/opt/anaconda3/lib/python3.7/site-packages/werkzeug/serving.py in run_simple(hostname, port, application, use_reloader, use_debugger, use_evalex, extra_files, reloader_interval, reloader_type, threaded, processes, request_handler, static_files, passthrough_errors, ssl_context)
1006 from ._reloader import run_with_reloader
1007
-> 1008 run_with_reloader(inner, extra_files, reloader_interval, reloader_type)
1009 else:
1010 inner()
~/opt/anaconda3/lib/python3.7/site-packages/werkzeug/_reloader.py in run_with_reloader(main_func, extra_files, interval, reloader_type)
337 reloader.run()
338 else:
--> 339 sys.exit(reloader.restart_with_reloader())
340 except KeyboardInterrupt:
341 pass
SystemExit: 1
In [4]:
from flask import Flask, request, render_template, jsonify
import requests
from IPython.display import display, HTML
import threading
app = Flask(__name__, template_folder='templates')
@app.route('/')
def home():
return render_template('index.html')
@app.route('/search', methods=['POST'])
def search():
query = request.form.get('query')
# Send the query to the ChatGPT API
chatgpt_url = 'https://api.openai.com/v1/engines/davinci-codex/completions'
chatgpt_headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer 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',
}
chatgpt_data = {
'prompt': query,
'max_tokens': 60,
}
response = requests.post(chatgpt_url, headers=chatgpt_headers, json=chatgpt_data)
chatgpt_response = response.json()
# Send a request to the Google Places API
places_url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
places_params = {
'query': query,
'key': 'AIzaSyAuHb4dRygN_UdzmqLPmdHd54UwshhbjgY',
}
response = requests.get(places_url, params=places_params)
places_response = response.json()
# Process the responses and extract relevant information
# TODO: Implement your logic here
# Create a response object with the extracted information
result = {
'query': query,
'chatgpt_response': chatgpt_response,
'places_response': places_response,
}
return jsonify(result)
def run_flask_app_in_background(app):
"""
Run a flask app in a background thread and open it in a browser window.
"""
def run_app():
app.run(port=5000)
def open_browser():
import webbrowser
webbrowser.open("http://localhost:5000/")
threading.Thread(target=run_app).start()
threading.Thread(target=open_browser).start()
run_flask_app_in_background(app)
* Serving Flask app "__main__" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
In [5]:
pip install gunicorn
Collecting gunicorn
Downloading https://files.pythonhosted.org/packages/e4/dd/5b190393e6066286773a67dfcc2f9492058e9b57c4867a95f1ba5caf0a83/gunicorn-20.1.0-py3-none-any.whl (79kB)
|████████████████████████████████| 81kB 3.0MB/s eta 0:00:01
Requirement already satisfied: setuptools>=3.0 in ./opt/anaconda3/lib/python3.7/site-packages (from gunicorn) (41.4.0)
Installing collected packages: gunicorn
Successfully installed gunicorn-20.1.0
Note: you may need to restart the kernel to use updated packages.
In [6]:
from flask import Flask, request, render_template
import requests
app = Flask(__name__, template_folder='templates')
@app.route('/')
def home():
return render_template('index.html')
@app.route('/search', methods=['POST'])
def search():
query = request.form.get('query')
# Send the query to the ChatGPT API
chatgpt_url = 'https://api.openai.com/v1/engines/davinci-codex/completions'
chatgpt_headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_CHATGPT_API_KEY',
}
chatgpt_data = {
'prompt': query,
'max_tokens': 60,
}
response = requests.post(chatgpt_url, headers=chatgpt_headers, json=chatgpt_data)
chatgpt_response = response.json()
# Send a request to the Google Places API
places_url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
places_params = {
'query': query,
'key': 'AIzaSyAuHb4dRygN_UdzmqLPmdHd54UwshhbjgY',
}
response = requests.get(places_url, params=places_params)
places_response = response.json()
return 'Results for: ' + query
if __name__ == '__main__':
app.run()
* Serving Flask app "__main__" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
In [7]:
gunicorn Untitled1:app
File "<ipython-input-7-9c8abaa1d75b>", line 1
gunicorn Untitled1:app
^
SyntaxError: invalid syntax
In [ ]:
from flask import Flask, request, render_template
import requests
app = Flask(__name__, template_folder='templates')
@app.route('/')
def home():
return render_template('index.html')
@app.route('/search', methods=['POST'])
def search():
query = request.form.get('query')
# Send the query to the ChatGPT API
chatgpt_url = 'https://api.openai.com/v1/engines/davinci-codex/completions'
chatgpt_headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer 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',
}
chatgpt_data = {
'prompt': query,
'max_tokens': 60,
}
response = requests.post(chatgpt_url, headers=chatgpt_headers, json=chatgpt_data)
chatgpt_response = response.json()
# Send a request to the Google Places API
places_url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
places_params = {
'query': query,
'key': 'AIzaSyAuHb4dRygN_UdzmqLPmdHd54UwshhbjgY',
}
response = requests.get(places_url, params=places_params)
places_response = response.json()
return 'Results for: ' + query
if __name__ == '__main__':
app.run()
* Serving Flask app "__main__" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [11/Jun/2023 19:54:34] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [11/Jun/2023 19:54:34] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [11/Jun/2023 19:54:40] "POST /search2 HTTP/1.1" 404 -
127.0.0.1 - - [11/Jun/2023 19:54:40] "POST /search2 HTTP/1.1" 404 -
127.0.0.1 - - [11/Jun/2023 19:54:40] "POST /search2 HTTP/1.1" 404 -
127.0.0.1 - - [11/Jun/2023 19:54:40] "POST /search2 HTTP/1.1" 404 -
In [ ]:
gunicorn 'Untitled 1':app
In [1]:
app.run()
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-b72f3165c8a5> in <module>
----> 1 app.run()
NameError: name 'app' is not defined
In [ ]:
!pip install jupyter_contrib_nbextensions && jupyter contrib nbextension install
In [ ]:
!jupyter nbextension enable --py latex --sys-prefix
In [1]:
xelatex --version
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-f56de67e45ac> in <module>
----> 1 xelatex --version
NameError: name 'xelatex' is not defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment