forked from PromtEngineer/localGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
50 changed files
with
65,254 additions
and
5,017 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,58 @@ | ||
from flask import Flask, render_template, request | ||
from werkzeug.utils import secure_filename | ||
import tempfile | ||
|
||
import os | ||
import sys | ||
import tempfile | ||
|
||
import requests | ||
from flask import Flask, render_template, request | ||
from werkzeug.utils import secure_filename | ||
|
||
sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | ||
sys.path.append(os.path.join(os.path.dirname(__file__), "..")) | ||
|
||
app = Flask(__name__) | ||
app.secret_key = "LeafmanZSecretKey" | ||
|
||
### PAGES ### | ||
@app.route('/', methods=['GET', 'POST']) | ||
|
||
# PAGES # | ||
@app.route("/", methods=["GET", "POST"]) | ||
def home_page(): | ||
if request.method == 'POST': | ||
if 'user_prompt' in request.form: | ||
user_prompt = request.form['user_prompt'] | ||
print(f'User Prompt: {user_prompt}') | ||
main_prompt_url = 'http://localhost:5110/api/prompt_route' | ||
response = requests.post(main_prompt_url, data={'user_prompt': user_prompt}) | ||
if request.method == "POST": | ||
if "user_prompt" in request.form: | ||
user_prompt = request.form["user_prompt"] | ||
print(f"User Prompt: {user_prompt}") | ||
|
||
main_prompt_url = "http://localhost:5110/api/prompt_route" | ||
response = requests.post(main_prompt_url, data={"user_prompt": user_prompt}) | ||
print(response.status_code) # print HTTP response status code for debugging | ||
if response.status_code == 200: | ||
# print(response.json()) # Print the JSON data from the response | ||
return render_template('home.html', show_response_modal=True, response_dict = response.json()) | ||
elif 'documents' in request.files: | ||
delete_source_url = 'http://localhost:5110/api/delete_source' # URL of the /api/delete_source endpoint | ||
if request.form.get('action') == 'reset': | ||
return render_template("home.html", show_response_modal=True, response_dict=response.json()) | ||
elif "documents" in request.files: | ||
delete_source_url = "http://localhost:5110/api/delete_source" # URL of the /api/delete_source endpoint | ||
if request.form.get("action") == "reset": | ||
response = requests.get(delete_source_url) | ||
|
||
save_document_url = 'http://localhost:5110/api/save_document' | ||
run_ingest_url = 'http://localhost:5110/api/run_ingest' # URL of the /api/run_ingest endpoint | ||
files = request.files.getlist('documents') | ||
save_document_url = "http://localhost:5110/api/save_document" | ||
run_ingest_url = "http://localhost:5110/api/run_ingest" # URL of the /api/run_ingest endpoint | ||
files = request.files.getlist("documents") | ||
for file in files: | ||
print(file.filename) | ||
filename = secure_filename(file.filename) | ||
with tempfile.SpooledTemporaryFile() as f: | ||
f.write(file.read()) | ||
f.seek(0) | ||
response = requests.post(save_document_url, files={'document': (filename, f)}) | ||
print(response.status_code) # print HTTP response status code for debugging | ||
f.write(file.read()) | ||
f.seek(0) | ||
response = requests.post(save_document_url, files={"document": (filename, f)}) | ||
print(response.status_code) # print HTTP response status code for debugging | ||
# Make a GET request to the /api/run_ingest endpoint | ||
response = requests.get(run_ingest_url) | ||
print(response.status_code) # print HTTP response status code for debugging | ||
|
||
# Display the form for GET request | ||
return render_template('home.html', show_response_modal=False, response_dict={'Prompt': 'None','Answer': 'None', 'Sources': [('ewf','wef')]}) | ||
if __name__ == '__main__': | ||
app.run(debug=False, port =5111) | ||
return render_template( | ||
"home.html", | ||
show_response_modal=False, | ||
response_dict={"Prompt": "None", "Answer": "None", "Sources": [("ewf", "wef")]}, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(debug=False, port=5111) |
Oops, something went wrong.