scottleibrand / gpt-summarizer

Extract text from PDF, summarize each section w/ GPT, and provide a summarized outline of the paper
MIT License
188 stars 27 forks source link

How to run this program? #8

Open cuchisavila opened 1 year ago

cuchisavila commented 1 year ago

Hi As someone who is new to this, how do I run your code? Can I get a step-by-step? I ran what you wrote in the read me in terminal on a mac

pip install pdfminer
pip install html2text
pip install tiktoken
pip install openai
export OPENAI_API_KEY=<your OpenAI API key>
python summarize.py paper.pdf

but it's not working.


when running (base) Bobbys-iMac:~ ROMs$ python summarize.py paper.pdf
python: can't open file '/Users/bobby/summarize.py': [Errno 2] No such file or directory

then I tried to copy and paste code from summary.py into a file and added an actual PdF document to that folder and got

(base) Bobbys-iMac:gpt-summarizer ROMs$ python summarize.py ABB525.pdf
  File "/Users/bobby/Documents/gpt-summarizer/summarize.py", line 1
    {\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf610
      ^
SyntaxError: unexpected character after line continuation character

Then I tried copying the same code using Jupiter notebook and then downloading that file and running with that code:

(base) Bobbys-iMac:gpt-summarizer ROMs$ python summarize.py AB525.pdf
Traceback (most recent call last):
  File "/Users/bobby/Documents/gpt-summarizer/summarize.py", line 28, in <module>
    "execution_count": null,
NameError: name 'null' is not defined

Then I tried:

(base) Bobbys-iMac:gpt-summarizer ROMs$ ./summarize.py https://www.energy.ca.gov/filebrowser/download/4361
-bash: ./summarize.py: Permission denied

Then tried:

(base) Bobbys-iMac:gpt-summarizer ROMs$ summarize.py https://www.energy.ca.gov/filebrowser/download/4361
-bash: summarize.py: command not found

how do I run your code?! HELP!!

Thank you

scottleibrand commented 1 year ago

python summarize.py paper.pdf will only work if the summarize.py is in your the directory you're currently in. If it's in some other directory, you need to provide the path to that location. One trick to doing that on a Mac is to drag and drop the file into Terminal. You can type python, then drag and drop the summarize.py file from Finder, and it will populate the full path to the file. Then you can hit space and do the same thing with your PDF.

If you want to be able to do ./summarize.py instead of python summarize.py, you'll need to make summarize.py executable first. The way to do that is chmod +x ./summarize.py.

Another trick if you get stuck is to open up ChatGPT, explain what you're trying to do, and copy and paste the full command and the error you get. It'll explain in detail (without assuming too much prior knowledge) what appears to be happening, and suggest some other things to try. You can also ask it follow-up questions in real time, or give it the output of the next thing you try if that also has an error.