Skip to content

Commit

Permalink
make it better
Browse files Browse the repository at this point in the history
  • Loading branch information
LeafmanZ committed Jun 19, 2023
1 parent 4b74b3a commit 73ee6bb
Show file tree
Hide file tree
Showing 50 changed files with 65,254 additions and 5,017 deletions.
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,27 @@ python run_localGPT.py --device_type cpu
```

# Run the UI

1. Start by opening up `run_localGPTAPI.py` in a code editor of your choice. If you are using gpu skip to step 3.

2. If you are running on cpu change `DEVICE_TYPE = 'cuda'` to `DEVICE_TYPE = 'cpu'`.

* Comment out the following:
```shell
model_id = "TheBloke/WizardLM-7B-uncensored-GPTQ"
model_basename = "WizardLM-7B-uncensored-GPTQ-4bit-128g.compat.no-act-order.safetensors"
LLM = load_model(device_type=DEVICE_TYPE, model_id=model_id, model_basename = model_basename)
```
* Uncomment:
```shell
model_id = "TheBloke/guanaco-7B-HF" # or some other -HF or .bin model
LLM = load_model(device_type=DEVICE_TYPE, model_id=model_id)
```

* If you are running gpu there should be nothing to change. Save and close `run_localGPTAPI.py`.
- Comment out the following:

```shell
model_id = "TheBloke/WizardLM-7B-uncensored-GPTQ"
model_basename = "WizardLM-7B-uncensored-GPTQ-4bit-128g.compat.no-act-order.safetensors"
LLM = load_model(device_type=DEVICE_TYPE, model_id=model_id, model_basename = model_basename)
```

- Uncomment:

```shell
model_id = "TheBloke/guanaco-7B-HF" # or some other -HF or .bin model
LLM = load_model(device_type=DEVICE_TYPE, model_id=model_id)
```

- If you are running gpu there should be nothing to change. Save and close `run_localGPTAPI.py`.

3. Open up a terminal and activate your python environment that contains the dependencies installed from requirements.txt.

Expand Down
65 changes: 36 additions & 29 deletions localGPTUI/localGPTUI.py
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)
Loading

0 comments on commit 73ee6bb

Please sign in to comment.