A script that empowers a user to upload a document and ask questions of ChatGPT for document analysis. Download the script and add your own api key.
-
Go to OpenAI's website (https://beta.openai.com/docs/guides/how-to-use-openai) and sign up for an account.
-
After you have signed up, go to the API Key section and generate an API Key.
-
Copy the API Key to your clipboard.
-
Open the Python script in your preferred code editor.
-
In the script, find line 14:
openai.api_key = "INSERT-CHATGPT-API-KEY-HERE"
- Replace "INSERT-CHATGPT-API-KEY-HERE" with the API Key you copied in step 3, between the quotation marks.
- Pre-requisites:
- Install Python 3 on your computer.
- Install the required libraries (openai, time, socket, os, and tkinter).
- Ensure that the document you want to upload (if you choose to upload a document) is in the same directory as the script.
- Run the script by executing the following command in your terminal or command prompt:
python3 script.py
- You will be prompted with a dialog asking whether you want to upload a document or ask a question directly. Choose your option by typing 1 or 2 and pressing Enter.
+---------------------------------------------------+
| |
| Choose an option: |
| 1. Upload a document |
| 2. Ask a question directly |
| |
+---------------------------------------------------+
-
If you choose option 1, a file dialog will appear, allowing you to select the document you want to ask questions about.
-
If you choose option 2, you will be prompted to enter your question directly.
+---------------------------------------------------+
| |
| Enter your question: |
| |
+---------------------------------------------------+
- After entering your question, the answer will be displayed on the screen.
+---------------------------------------------------+
| |
| Answer: |
| [Your answer will be displayed here] |
| |
+---------------------------------------------------+
- You will be prompted to ask another question or display all the results before saving to a file. Choose your option by typing 1 or 2 and pressing Enter.
+---------------------------------------------------+
| |
| What would you like to do next? |
| 1. Ask another question |
| 2. Display all results and save to a file |
| |
+---------------------------------------------------+
-
If you choose option 1, you will be taken back to step 5.
-
If you choose option 2, the results will be displayed on the screen, including the timestamp and the IP address of the source of the request. Then, you will be prompted to enter a filename to save the results.
+---------------------------------------------------+
| |
| Saving the results to a file |
| |
+---------------------------------------------------+
-
Enter a filename and press Enter to save the results to a file. The file will be saved in the same directory as the script.
-
The script will display a message confirming that the results have been saved successfully.
Results saved successfully!