Spaces:
Sleeping
Sleeping
te
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- chat_history.db +0 -0
- controllers/ai/.gpteng/memory/logs/all_output.txt +0 -0
- controllers/ai/.gpteng/memory/logs/gen_entrypoint_chat.txt +1844 -0
- controllers/ai/Structure +15 -16
- controllers/ai/app.py +16 -33
- controllers/ai/app/admin.py +3 -0
- controllers/ai/app/apps.py +5 -0
- controllers/ai/app/controllers/google_ocr.py +41 -0
- controllers/ai/app/controllers/logger.py +9 -0
- controllers/ai/app/controllers/ocr.py +11 -0
- controllers/ai/app/forms.py +7 -0
- controllers/ai/app/models.py +8 -0
- controllers/ai/app/templates/base.html +12 -0
- controllers/ai/app/templates/create_website.html +10 -0
- controllers/ai/app/templates/index.html +12 -0
- controllers/ai/app/templates/scrape_result.html +10 -0
- controllers/ai/app/urls.py +6 -0
- controllers/ai/app/views.py +6 -0
- controllers/ai/appscript.gs +38 -0
- controllers/ai/command +1 -0
- controllers/ai/commands +3 -0
- controllers/ai/gradio_app.py +22 -0
- controllers/ai/manage.py +15 -0
- controllers/ai/mysite/asgi.py +6 -0
- controllers/ai/mysite/settings.py +8 -0
- controllers/ai/mysite/urls.py +7 -0
- controllers/ai/polls/models.py +5 -0
- controllers/ai/polls/ocr.py +7 -0
- controllers/ai/polls/templates/base.html +16 -0
- controllers/ai/polls/templates/polls/index.html +17 -0
- controllers/ai/polls/urls.py +6 -0
- controllers/ai/polls/views.py +27 -0
- controllers/ai/project/settings.py +69 -0
- controllers/ai/project/urls.py +7 -0
- controllers/ai/project/wsgi.py +7 -0
- controllers/ai/prompt +177 -1
- controllers/ai/requirements.txt +2 -5
- controllers/ai/run.sh +2 -3
- controllers/ai/static/css/style.css +51 -0
- controllers/ai/templates/base.html +21 -0
- controllers/ai/templates/index.html +9 -31
- controllers/ai/templates/specification.html +17 -0
- controllers/gra_02_openInterpreter/OpenInterpreter.py +62 -18
- controllers/test_folders/prompt +0 -21
- controllers/test_folderszd/requirements.txt +0 -1
- projectname/manage.py +22 -0
- {controllers/test_folders → projectname/pollss}/__init__.py +0 -0
- projectname/pollss/admin.py +3 -0
- projectname/pollss/apps.py +6 -0
- {controllers/test_plantuml → projectname/pollss/migrations}/__init__.py +0 -0
chat_history.db
ADDED
Binary file (147 kB). View file
|
|
controllers/ai/.gpteng/memory/logs/all_output.txt
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
controllers/ai/.gpteng/memory/logs/gen_entrypoint_chat.txt
CHANGED
@@ -2204,3 +2204,1847 @@ python app.py &
|
|
2204 |
gradio app.py &
|
2205 |
```
|
2206 |
Note: The `&` at the end of each command runs them in the background, allowing them to run in parallel.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2204 |
gradio app.py &
|
2205 |
```
|
2206 |
Note: The `&` at the end of each command runs them in the background, allowing them to run in parallel.
|
2207 |
+
|
2208 |
+
2024-06-10T15:28:21.255540
|
2209 |
+
================================ System Message ================================
|
2210 |
+
|
2211 |
+
You will get information about a codebase that is currently on disk in the current folder.
|
2212 |
+
The user will ask you to write a script that runs the code in a specific way.
|
2213 |
+
You will answer with code blocks that include all the necessary terminal commands.
|
2214 |
+
Do not install globally. Do not use sudo.
|
2215 |
+
Do not explain the code, just give the commands.
|
2216 |
+
Do not use placeholders, use example values (like . for a folder argument) if necessary.
|
2217 |
+
|
2218 |
+
|
2219 |
+
================================ Human Message =================================
|
2220 |
+
|
2221 |
+
|
2222 |
+
Make a unix script that
|
2223 |
+
a) installs dependencies
|
2224 |
+
b) runs all necessary parts of the codebase (in parallel if necessary)
|
2225 |
+
|
2226 |
+
Information about the codebase:
|
2227 |
+
|
2228 |
+
```
|
2229 |
+
File: requirements.txt
|
2230 |
+
1 Flask==2.0.1
|
2231 |
+
2 gradio==2.9.9
|
2232 |
+
3 pytesseract==0.3.8
|
2233 |
+
4 plantuml==0.8.1
|
2234 |
+
|
2235 |
+
File: app.py
|
2236 |
+
1 from flask import Flask, request, jsonify
|
2237 |
+
2 import pytesseract
|
2238 |
+
3 from PIL import Image
|
2239 |
+
4 import gradio as gr
|
2240 |
+
5 from plantuml import PlantUML
|
2241 |
+
6
|
2242 |
+
7 app = Flask(__name__)
|
2243 |
+
8
|
2244 |
+
9 # Initialize PlantUML
|
2245 |
+
10 plantuml = PlantUML()
|
2246 |
+
11
|
2247 |
+
12 @app.route('/ocr', methods=['POST'])
|
2248 |
+
13 def ocr():
|
2249 |
+
14 img = request.files['image']
|
2250 |
+
15 img.save('temp.jpg')
|
2251 |
+
16 text = pytesseract.image_to_string(Image.open('temp.jpg'))
|
2252 |
+
17 return jsonify({'text': text})
|
2253 |
+
18
|
2254 |
+
19 @app.route('/plantuml', methods=['POST'])
|
2255 |
+
20 def plantuml_diagram():
|
2256 |
+
21 code = request.form['code']
|
2257 |
+
22 diagram = plantuml.get_svg_string(code)
|
2258 |
+
23 return jsonify({'diagram': diagram})
|
2259 |
+
24
|
2260 |
+
25 if __name__ == '__main__':
|
2261 |
+
26 app.run(debug=True)
|
2262 |
+
|
2263 |
+
File: gradio_app.py
|
2264 |
+
1 import gradio as gr
|
2265 |
+
2 from app import app
|
2266 |
+
3
|
2267 |
+
4 with gr.Blocks() as demo:
|
2268 |
+
5 img = gr.Image(type="pil")
|
2269 |
+
6 btn = gr.Button("Run OCR")
|
2270 |
+
7 txt = gr.Textbox(label="Extracted Text")
|
2271 |
+
8 plantuml_code = gr.Textbox(label="PlantUML Code")
|
2272 |
+
9 plantuml_diagram = gr.Image(type="pil")
|
2273 |
+
10
|
2274 |
+
11 def ocr(img):
|
2275 |
+
12 response = app.post('/ocr', files={'image': img})
|
2276 |
+
13 return response.json()['text']
|
2277 |
+
14
|
2278 |
+
15 def plantuml_diagram(code):
|
2279 |
+
16 response = app.post('/plantuml', data={'code': code})
|
2280 |
+
17 return response.json()['diagram']
|
2281 |
+
18
|
2282 |
+
19 btn.click(ocr, inputs=img, outputs=txt)
|
2283 |
+
20 btn.click(plantuml_diagram, inputs=plantuml_code, outputs=plantuml_diagram)
|
2284 |
+
21
|
2285 |
+
22 demo.launch()
|
2286 |
+
|
2287 |
+
File: templates/index.html
|
2288 |
+
1 <!DOCTYPE html>
|
2289 |
+
2 <html>
|
2290 |
+
3 <head>
|
2291 |
+
4 <title>OCR and PlantUML Demo</title>
|
2292 |
+
5 </head>
|
2293 |
+
6 <body>
|
2294 |
+
7 <h1>OCR and PlantUML Demo</h1>
|
2295 |
+
8 <form>
|
2296 |
+
9 <input type="file" id="image" name="image">
|
2297 |
+
10 <button id="run-ocr">Run OCR</button>
|
2298 |
+
11 <div id="extracted-text"></div>
|
2299 |
+
12 <h2>PlantUML</h2>
|
2300 |
+
13 <textarea id="plantuml-code" name="plantuml-code"></textarea>
|
2301 |
+
14 <button id="generate-diagram">Generate Diagram</button>
|
2302 |
+
15 <div id="plantuml-diagram"></div>
|
2303 |
+
16 </form>
|
2304 |
+
17
|
2305 |
+
18 <script src="https://cdn.jsdelivr.net/npm/gradio@2.9.9/dist/gradio.min.js"></script>
|
2306 |
+
19 <script>
|
2307 |
+
20 const imgInput = document.getElementById('image');
|
2308 |
+
21 const runOcrBtn = document.getElementById('run-ocr');
|
2309 |
+
22 const extractedTextDiv = document.getElementById('extracted-text');
|
2310 |
+
23 const plantumlCodeTextarea = document.getElementById('plantuml-code');
|
2311 |
+
24 const generateDiagramBtn = document.getElementById('generate-diagram');
|
2312 |
+
25 const plantumlDiagramDiv = document.getElementById('plantuml-diagram');
|
2313 |
+
26
|
2314 |
+
27 runOcrBtn.addEventListener('click', async () => {
|
2315 |
+
28 const formData = new FormData();
|
2316 |
+
29 formData.append('image', imgInput.files[0]);
|
2317 |
+
30 const response = await fetch('/ocr', {
|
2318 |
+
31 method: 'POST',
|
2319 |
+
32 body: formData
|
2320 |
+
33 });
|
2321 |
+
34 const text = await response.json();
|
2322 |
+
35 extractedTextDiv.innerText = text.text;
|
2323 |
+
36 });
|
2324 |
+
37
|
2325 |
+
38 generateDiagramBtn.addEventListener('click', async () => {
|
2326 |
+
39 const code = plantumlCodeTextarea.value;
|
2327 |
+
40 const response = await fetch('/plantuml', {
|
2328 |
+
41 method: 'POST',
|
2329 |
+
42 headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
2330 |
+
43 body: `code=${code}`
|
2331 |
+
44 });
|
2332 |
+
45 const diagram = await response.json();
|
2333 |
+
46 plantumlDiagramDiv.innerHTML = diagram.diagram;
|
2334 |
+
47 });
|
2335 |
+
48 </script>
|
2336 |
+
49 </body>
|
2337 |
+
50 </html>
|
2338 |
+
|
2339 |
+
```
|
2340 |
+
|
2341 |
+
================================== Ai Message ==================================
|
2342 |
+
|
2343 |
+
Here is the Unix script that installs dependencies and runs the codebase:
|
2344 |
+
```
|
2345 |
+
#!/bin/bash
|
2346 |
+
|
2347 |
+
# Install dependencies
|
2348 |
+
python -m pip install -r requirements.txt
|
2349 |
+
|
2350 |
+
# Run the Flask app
|
2351 |
+
python app.py &
|
2352 |
+
|
2353 |
+
# Run the Gradio app
|
2354 |
+
python gradio_app.py
|
2355 |
+
```
|
2356 |
+
Note: The `&` at the end of the `python app.py` line runs the Flask app in the background, allowing the Gradio app to run concurrently.
|
2357 |
+
|
2358 |
+
2024-06-10T15:30:15.274707
|
2359 |
+
================================ System Message ================================
|
2360 |
+
|
2361 |
+
You will get information about a codebase that is currently on disk in the current folder.
|
2362 |
+
The user will ask you to write a script that runs the code in a specific way.
|
2363 |
+
You will answer with code blocks that include all the necessary terminal commands.
|
2364 |
+
Do not install globally. Do not use sudo.
|
2365 |
+
Do not explain the code, just give the commands.
|
2366 |
+
Do not use placeholders, use example values (like . for a folder argument) if necessary.
|
2367 |
+
|
2368 |
+
|
2369 |
+
================================ Human Message =================================
|
2370 |
+
|
2371 |
+
|
2372 |
+
Make a unix script that
|
2373 |
+
a) installs dependencies
|
2374 |
+
b) runs all necessary parts of the codebase (in parallel if necessary)
|
2375 |
+
|
2376 |
+
Information about the codebase:
|
2377 |
+
|
2378 |
+
```
|
2379 |
+
File: requirements.txt
|
2380 |
+
1 Django==3.2.5
|
2381 |
+
2 django-gradio==0.2.1
|
2382 |
+
3 google-api-python-client==2.34.0
|
2383 |
+
4 google-auth-httplib2==0.1.0
|
2384 |
+
5 google-auth-oauthlib==0.5.3
|
2385 |
+
6 pytesseract==0.3.10
|
2386 |
+
|
2387 |
+
File: polls/models.py
|
2388 |
+
1 from django.db import models
|
2389 |
+
2
|
2390 |
+
3 class ImageModel(models.Model):
|
2391 |
+
4 image = models.ImageField(upload_to='images/')
|
2392 |
+
5 ocr_text = models.TextField(blank=True)
|
2393 |
+
|
2394 |
+
File: polls/views.py
|
2395 |
+
1 from django.shortcuts import render
|
2396 |
+
2 from django.core.files.storage import FileSystemStorage
|
2397 |
+
3 from django.conf import settings
|
2398 |
+
4 import pytesseract
|
2399 |
+
5 from google.oauth2 import service_account
|
2400 |
+
6 from googleapiclient.discovery import build
|
2401 |
+
7 from googleapiclient.errors import HttpError
|
2402 |
+
8
|
2403 |
+
9 def index(request):
|
2404 |
+
10 if request.method == 'POST':
|
2405 |
+
11 image = request.FILES['image']
|
2406 |
+
12 fs = FileSystemStorage()
|
2407 |
+
13 filename = fs.save(image.name, image)
|
2408 |
+
14 uploaded_file_url = fs.url(filename)
|
2409 |
+
15 ocr_text = pytesseract.image_to_string(settings.MEDIA_ROOT + '/' + filename)
|
2410 |
+
16 ImageModel.objects.create(image=filename, ocr_text=ocr_text)
|
2411 |
+
17 return render(request, 'polls/index.html', {'uploaded_file_url': uploaded_file_url, 'ocr_text': ocr_text})
|
2412 |
+
18 return render(request, 'polls/index.html')
|
2413 |
+
19
|
2414 |
+
20 def google_chat_insert(text):
|
2415 |
+
21 SCOPES = ['https://www.googleapis.com/auth/chat.service']
|
2416 |
+
22 SERVICE_ACCOUNT_FILE = 'service_account_key.json'
|
2417 |
+
23 credentials = service_account.Credentials.from_service_account_file(
|
2418 |
+
24 SERVICE_ACCOUNT_FILE, SCOPES)
|
2419 |
+
25 chat_service = build('chat', 'v1', credentials=credentials)
|
2420 |
+
26 request_body = {'text': text}
|
2421 |
+
27 response = chat_service.spaces().messages().create(
|
2422 |
+
28 parent='spaces/AAAAjKdFV6A', body=request_body).execute()
|
2423 |
+
29 print(response)
|
2424 |
+
|
2425 |
+
File: polls/templates/polls/index.html
|
2426 |
+
1 <!DOCTYPE html>
|
2427 |
+
2 <html>
|
2428 |
+
3 <head>
|
2429 |
+
4 <title>OCR App</title>
|
2430 |
+
5 </head>
|
2431 |
+
6 <body>
|
2432 |
+
7 <h1>OCR App</h1>
|
2433 |
+
8 <form method="post" enctype="multipart/form-data">
|
2434 |
+
9 {% csrf_token %}
|
2435 |
+
10 <input type="file" name="image">
|
2436 |
+
11 <button type="submit">Upload</button>
|
2437 |
+
12 </form>
|
2438 |
+
13 {% if uploaded_file_url %}
|
2439 |
+
14 <p>Uploaded image: <a href="{{ uploaded_file_url }}">{{ uploaded_file_url }}</a></p>
|
2440 |
+
15 <p>OCR Text: {{ ocr_text }}</p>
|
2441 |
+
16 {% endif %}
|
2442 |
+
17 </body>
|
2443 |
+
18 </html>
|
2444 |
+
|
2445 |
+
File: polls/urls.py
|
2446 |
+
1 from django.urls import path
|
2447 |
+
2 from . import views
|
2448 |
+
3
|
2449 |
+
4 urlpatterns = [
|
2450 |
+
5 path('', views.index, name='index'),
|
2451 |
+
6 ]
|
2452 |
+
|
2453 |
+
File: mysite/urls.py
|
2454 |
+
1 from django.contrib import admin
|
2455 |
+
2 from django.urls import include, path
|
2456 |
+
3
|
2457 |
+
4 urlpatterns = [
|
2458 |
+
5 path('polls/', include('polls.urls')),
|
2459 |
+
6 path('admin/', admin.site.urls),
|
2460 |
+
7 ]
|
2461 |
+
|
2462 |
+
File: mysite/settings.py
|
2463 |
+
1 MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
2464 |
+
2 MEDIA_URL = '/media/'
|
2465 |
+
|
2466 |
+
File: service_account_key.json
|
2467 |
+
1 {
|
2468 |
+
2 "type": "service_account",
|
2469 |
+
3 "project_id": "your-project-id",
|
2470 |
+
4 "private_key_id": "your-private-key-id",
|
2471 |
+
5 "private_key": "your-private-key",
|
2472 |
+
6 "client_email": "your-client-email",
|
2473 |
+
7 "client_id": "your-client-id",
|
2474 |
+
8 "auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
2475 |
+
9 "token_uri": "https://oauth2.googleapis.com/token",
|
2476 |
+
10 "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
2477 |
+
11 "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/your-service-account-email"
|
2478 |
+
12 }
|
2479 |
+
|
2480 |
+
```
|
2481 |
+
|
2482 |
+
================================== Ai Message ==================================
|
2483 |
+
|
2484 |
+
Here is the Unix script that installs dependencies and runs the codebase:
|
2485 |
+
|
2486 |
+
```bash
|
2487 |
+
#!/bin/bash
|
2488 |
+
|
2489 |
+
# Install dependencies
|
2490 |
+
python -m pip install -r requirements.txt
|
2491 |
+
|
2492 |
+
# Run the Django development server
|
2493 |
+
python manage.py runserver
|
2494 |
+
```
|
2495 |
+
|
2496 |
+
Note: This script assumes that you are in the root directory of your Django project, and that you have a `manage.py` file in that directory.
|
2497 |
+
|
2498 |
+
2024-06-10T15:32:29.966162
|
2499 |
+
================================ System Message ================================
|
2500 |
+
|
2501 |
+
You will get information about a codebase that is currently on disk in the current folder.
|
2502 |
+
The user will ask you to write a script that runs the code in a specific way.
|
2503 |
+
You will answer with code blocks that include all the necessary terminal commands.
|
2504 |
+
Do not install globally. Do not use sudo.
|
2505 |
+
Do not explain the code, just give the commands.
|
2506 |
+
Do not use placeholders, use example values (like . for a folder argument) if necessary.
|
2507 |
+
|
2508 |
+
|
2509 |
+
================================ Human Message =================================
|
2510 |
+
|
2511 |
+
|
2512 |
+
Make a unix script that
|
2513 |
+
a) installs dependencies
|
2514 |
+
b) runs all necessary parts of the codebase (in parallel if necessary)
|
2515 |
+
|
2516 |
+
Information about the codebase:
|
2517 |
+
|
2518 |
+
```
|
2519 |
+
File: requirements.txt
|
2520 |
+
1 Django==3.2.5
|
2521 |
+
2 google-api-python-client==2.34.0
|
2522 |
+
3 google-auth-httplib2==0.1.0
|
2523 |
+
4 google-auth-oauthlib==0.5.3
|
2524 |
+
5 gradio==2.9.9
|
2525 |
+
6 plantuml==0.3.1
|
2526 |
+
|
2527 |
+
File: polls/models.py
|
2528 |
+
1 from django.db import models
|
2529 |
+
2
|
2530 |
+
3 class OcrResult(models.Model):
|
2531 |
+
4 text = models.TextField()
|
2532 |
+
5 created_at = models.DateTimeField(auto_now_add=True)
|
2533 |
+
|
2534 |
+
File: polls/views.py
|
2535 |
+
1 from django.shortcuts import HttpResponse
|
2536 |
+
2 from .models import OcrResult
|
2537 |
+
3 import os
|
2538 |
+
4 import requests
|
2539 |
+
5 from google.oauth2 import service_account
|
2540 |
+
6 from googleapiclient.discovery import build
|
2541 |
+
7 from googleapiclient.errors import HttpError
|
2542 |
+
8 import gradio as gr
|
2543 |
+
9 from plantuml import PlantUML
|
2544 |
+
10
|
2545 |
+
11 def ocr_view(request):
|
2546 |
+
12 if request.method == 'POST':
|
2547 |
+
13 img_ocr = request.POST.get('img_ocr')
|
2548 |
+
14 ocr_result = OcrResult(text=img_ocr)
|
2549 |
+
15 ocr_result.save()
|
2550 |
+
16 return HttpResponse('OCR result saved successfully')
|
2551 |
+
17 return HttpResponse('Invalid request')
|
2552 |
+
18
|
2553 |
+
19 def google_chat_insert(text):
|
2554 |
+
20 SCOPES = ['https://www.googleapis.com/auth/chat.serviceagent']
|
2555 |
+
21 SERVICE_ACCOUNT_FILE = 'path/to/service_account_key.json'
|
2556 |
+
22 credentials = service_account.Credentials.from_service_account_file(
|
2557 |
+
23 SERVICE_ACCOUNT_FILE, scopes=SCOPES)
|
2558 |
+
24 chat_service = build('chat', 'v1', credentials=credentials)
|
2559 |
+
25 request_body = {'text': text}
|
2560 |
+
26 response = chat_service.spaces().messages().create(
|
2561 |
+
27 parent='spaces/AAAA', body=request_body).execute()
|
2562 |
+
28 return response
|
2563 |
+
29
|
2564 |
+
30 def plantuml_view(request):
|
2565 |
+
31 puml = PlantUML()
|
2566 |
+
32 puml.processes_file('path/to/plantuml/file.puml')
|
2567 |
+
33 return HttpResponse(puml.get_svg())
|
2568 |
+
|
2569 |
+
File: polls/urls.py
|
2570 |
+
1 from django.urls import path
|
2571 |
+
2 from . import views
|
2572 |
+
3
|
2573 |
+
4 urlpatterns = [
|
2574 |
+
5 path('ocr/', views.ocr_view, name='ocr_view'),
|
2575 |
+
6 path('plantuml/', views.plantuml_view, name='plantuml_view'),
|
2576 |
+
7 ]
|
2577 |
+
|
2578 |
+
File: polls/templates/base.html
|
2579 |
+
1 <!DOCTYPE html>
|
2580 |
+
2 <html>
|
2581 |
+
3 <head>
|
2582 |
+
4 <title>OCR App</title>
|
2583 |
+
5 </head>
|
2584 |
+
6 <body>
|
2585 |
+
7 <h1>OCR App</h1>
|
2586 |
+
8 <form method="post">
|
2587 |
+
9 {% csrf_token %}
|
2588 |
+
10 <input type="text" name="img_ocr" placeholder="Enter OCR result">
|
2589 |
+
11 <button type="submit">Save OCR result</button>
|
2590 |
+
12 </form>
|
2591 |
+
13 <hr>
|
2592 |
+
14 <a href="{% url 'plantuml_view' %}">View PlantUML diagram</a>
|
2593 |
+
15 </body>
|
2594 |
+
16 </html>
|
2595 |
+
|
2596 |
+
File: manage.py
|
2597 |
+
1 import os
|
2598 |
+
2 import sys
|
2599 |
+
3
|
2600 |
+
4 if __name__ == "__main__":
|
2601 |
+
5 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
|
2602 |
+
6 try:
|
2603 |
+
7 from django.core.management import execute_from_command_line
|
2604 |
+
8 except ImportError as exc:
|
2605 |
+
9 raise ImportError(
|
2606 |
+
10 "Couldn't import Django. Are you sure it's installed and "
|
2607 |
+
11 "available on your PYTHONPATH environment variable? Did you "
|
2608 |
+
12 "forget to activate a virtual environment?"
|
2609 |
+
13 ) from exc
|
2610 |
+
14 execute_from_command_line(sys.argv)
|
2611 |
+
|
2612 |
+
File: mysite/settings.py
|
2613 |
+
1 INSTALLED_APPS = [
|
2614 |
+
2 'django.contrib.admin',
|
2615 |
+
3 'django.contrib.auth',
|
2616 |
+
4 'django.contrib.contenttypes',
|
2617 |
+
5 'django.contrib.sessions',
|
2618 |
+
6 'django.contrib.messages',
|
2619 |
+
7 'django.contrib.staticfiles',
|
2620 |
+
8 'polls',
|
2621 |
+
9 ]
|
2622 |
+
10
|
2623 |
+
11 DATABASES = {
|
2624 |
+
12 'default': {
|
2625 |
+
13 'ENGINE': 'django.db.backends.sqlite3',
|
2626 |
+
14 'NAME': BASE_DIR / 'db.sqlite3',
|
2627 |
+
15 }
|
2628 |
+
16 }
|
2629 |
+
17
|
2630 |
+
18 STATIC_URL = '/static/'
|
2631 |
+
|
2632 |
+
File: mysite/urls.py
|
2633 |
+
1 from django.contrib import admin
|
2634 |
+
2 from django.urls import include, path
|
2635 |
+
3
|
2636 |
+
4 urlpatterns = [
|
2637 |
+
5 path('admin/', admin.site.urls),
|
2638 |
+
6 path('polls/', include('polls.urls')),
|
2639 |
+
7 ]
|
2640 |
+
|
2641 |
+
File: appscript.gs
|
2642 |
+
1 function onEdit(e) {
|
2643 |
+
2 var sheet = e.source.getActiveSheet();
|
2644 |
+
3 var range = e.range;
|
2645 |
+
4
|
2646 |
+
5 // Call Python script to process OCR result
|
2647 |
+
6 var pythonScript = "python manage.py ocr_view";
|
2648 |
+
7 var ocrResult = UrlFetchApp.fetch(pythonScript);
|
2649 |
+
8
|
2650 |
+
9 // Insert OCR result into Google Chat
|
2651 |
+
10 var chatService = getService();
|
2652 |
+
11 var spaceName = 'spaces/AAAA';
|
2653 |
+
12 var message = {'text': ocrResult.getContentText()};
|
2654 |
+
13 chatService.spaces.messages.create({
|
2655 |
+
14 'parent': spaceName,
|
2656 |
+
15 'resource': message
|
2657 |
+
16 });
|
2658 |
+
17 }
|
2659 |
+
18
|
2660 |
+
19 function getService() {
|
2661 |
+
20 var service = OAuth2.createService('chat')
|
2662 |
+
21 .setAuthorizationBaseUrl('https://accounts.google.com')
|
2663 |
+
22 .setTokenUrl('https://accounts.google.com/o/oauth2/token')
|
2664 |
+
23 .setClientId('your_client_id')
|
2665 |
+
24 .setClientSecret('your_client_secret')
|
2666 |
+
25 .setCallbackFunction('authCallback')
|
2667 |
+
26 .setPropertyStore(PropertiesService.getUserProperties());
|
2668 |
+
27 return service;
|
2669 |
+
28 }
|
2670 |
+
29
|
2671 |
+
30 function authCallback(request) {
|
2672 |
+
31 var service = getService();
|
2673 |
+
32 var authorized = service.handleCallback(request);
|
2674 |
+
33 if (authorized) {
|
2675 |
+
34 return HtmlService.createHtmlOutput('Authorized');
|
2676 |
+
35 } else {
|
2677 |
+
36 return HtmlService.createHtmlOutput('Not authorized');
|
2678 |
+
37 }
|
2679 |
+
38 }
|
2680 |
+
|
2681 |
+
```
|
2682 |
+
|
2683 |
+
================================== Ai Message ==================================
|
2684 |
+
|
2685 |
+
Here is the Unix script that installs dependencies and runs the codebase:
|
2686 |
+
|
2687 |
+
```bash
|
2688 |
+
#!/bin/bash
|
2689 |
+
|
2690 |
+
# Install dependencies
|
2691 |
+
python -m pip install --user -r requirements.txt
|
2692 |
+
|
2693 |
+
# Run the Django development server
|
2694 |
+
python manage.py runserver
|
2695 |
+
```
|
2696 |
+
|
2697 |
+
Note: This script assumes that you are running it from the root directory of the codebase.
|
2698 |
+
|
2699 |
+
2024-06-10T15:33:09.547336
|
2700 |
+
================================ System Message ================================
|
2701 |
+
|
2702 |
+
You will get information about a codebase that is currently on disk in the current folder.
|
2703 |
+
The user will ask you to write a script that runs the code in a specific way.
|
2704 |
+
You will answer with code blocks that include all the necessary terminal commands.
|
2705 |
+
Do not install globally. Do not use sudo.
|
2706 |
+
Do not explain the code, just give the commands.
|
2707 |
+
Do not use placeholders, use example values (like . for a folder argument) if necessary.
|
2708 |
+
|
2709 |
+
|
2710 |
+
================================ Human Message =================================
|
2711 |
+
|
2712 |
+
|
2713 |
+
Make a unix script that
|
2714 |
+
a) installs dependencies
|
2715 |
+
b) runs all necessary parts of the codebase (in parallel if necessary)
|
2716 |
+
|
2717 |
+
Information about the codebase:
|
2718 |
+
|
2719 |
+
```
|
2720 |
+
File: requirements.txt
|
2721 |
+
1 Django==3.2.5
|
2722 |
+
2 python-ocr==0.1.1
|
2723 |
+
3 google-api-python-client==2.34.0
|
2724 |
+
4 google-auth-httplib2==0.1.0
|
2725 |
+
5 google-auth-oauthlib==0.5.3
|
2726 |
+
|
2727 |
+
File: polls/models.py
|
2728 |
+
1 from django.db import models
|
2729 |
+
2
|
2730 |
+
3 class ImageModel(models.Model):
|
2731 |
+
4 image = models.ImageField(upload_to='images/')
|
2732 |
+
5 ocr_text = models.TextField(blank=True)
|
2733 |
+
|
2734 |
+
File: polls/views.py
|
2735 |
+
1 from django.shortcuts import render
|
2736 |
+
2 from .models import ImageModel
|
2737 |
+
3 from .ocr import ocr_extract_text
|
2738 |
+
4 from googleapiclient.discovery import build
|
2739 |
+
5 from google.oauth2 import service_account
|
2740 |
+
6
|
2741 |
+
7 def index(request):
|
2742 |
+
8 if request.method == 'POST':
|
2743 |
+
9 image = request.FILES['image']
|
2744 |
+
10 img_obj = ImageModel(image=image)
|
2745 |
+
11 img_obj.save()
|
2746 |
+
12 ocr_text = ocr_extract_text(img_obj.image.path)
|
2747 |
+
13 img_obj.ocr_text = ocr_text
|
2748 |
+
14 img_obj.save()
|
2749 |
+
15 return render(request, 'polls/index.html', {'ocr_text': ocr_text})
|
2750 |
+
16 return render(request, 'polls/index.html')
|
2751 |
+
17
|
2752 |
+
18 def google_chat_insert(text):
|
2753 |
+
19 SCOPES = ['https://www.googleapis.com/auth/chat.service']
|
2754 |
+
20 SERVICE_ACCOUNT_FILE = 'path/to/service_account_key.json'
|
2755 |
+
21 credentials = service_account.Credentials.from_service_account_file(
|
2756 |
+
22 SERVICE_ACCOUNT_FILE, scopes=SCOPES)
|
2757 |
+
23 chat_service = build('chat', 'v1', credentials=credentials)
|
2758 |
+
24 request_body = {'text': text}
|
2759 |
+
25 response = chat_service.spaces().messages().create(
|
2760 |
+
26 parent='spaces/AAAA', body=request_body).execute()
|
2761 |
+
27 print(response)
|
2762 |
+
|
2763 |
+
File: polls/ocr.py
|
2764 |
+
1 import pytesseract
|
2765 |
+
2 from PIL import Image
|
2766 |
+
3
|
2767 |
+
4 def ocr_extract_text(image_path):
|
2768 |
+
5 image = Image.open(image_path)
|
2769 |
+
6 text = pytesseract.image_to_string(image)
|
2770 |
+
7 return text
|
2771 |
+
|
2772 |
+
File: polls/templates/polls/index.html
|
2773 |
+
1 <!DOCTYPE html>
|
2774 |
+
2 <html>
|
2775 |
+
3 <head>
|
2776 |
+
4 <title>OCR App</title>
|
2777 |
+
5 </head>
|
2778 |
+
6 <body>
|
2779 |
+
7 <h1>OCR App</h1>
|
2780 |
+
8 <form method="post" enctype="multipart/form-data">
|
2781 |
+
9 {% csrf_token %}
|
2782 |
+
10 <input type="file" name="image">
|
2783 |
+
11 <button type="submit">Upload Image</button>
|
2784 |
+
12 </form>
|
2785 |
+
13 {% if ocr_text %}
|
2786 |
+
14 <p>Extracted Text: {{ ocr_text }}</p>
|
2787 |
+
15 {% endif %}
|
2788 |
+
16 </body>
|
2789 |
+
17 </html>
|
2790 |
+
|
2791 |
+
File: polls/urls.py
|
2792 |
+
1 from django.urls import path
|
2793 |
+
2 from . import views
|
2794 |
+
3
|
2795 |
+
4 urlpatterns = [
|
2796 |
+
5 path('', views.index, name='index'),
|
2797 |
+
6 ]
|
2798 |
+
|
2799 |
+
File: mysite/urls.py
|
2800 |
+
1 from django.contrib import admin
|
2801 |
+
2 from django.urls import include, path
|
2802 |
+
3
|
2803 |
+
4 urlpatterns = [
|
2804 |
+
5 path('polls/', include('polls.urls')),
|
2805 |
+
6 path('admin/', admin.site.urls),
|
2806 |
+
7 ]
|
2807 |
+
|
2808 |
+
File: mysite/settings.py
|
2809 |
+
1 INSTALLED_APPS = [
|
2810 |
+
2 # ...
|
2811 |
+
3 'polls.apps.PollsConfig',
|
2812 |
+
4 # ...
|
2813 |
+
5 ]
|
2814 |
+
6
|
2815 |
+
7 MEDIA_ROOT = 'media/'
|
2816 |
+
8 MEDIA_URL = '/media/'
|
2817 |
+
|
2818 |
+
File: mysite/asgi.py
|
2819 |
+
1 import os
|
2820 |
+
2 from django.core.asgi import get_asgi_application
|
2821 |
+
3
|
2822 |
+
4 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
|
2823 |
+
5
|
2824 |
+
6 application = get_asgi_application()
|
2825 |
+
|
2826 |
+
File: manage.py
|
2827 |
+
1 import os
|
2828 |
+
2 import sys
|
2829 |
+
3
|
2830 |
+
4 if __name__ == "__main__":
|
2831 |
+
5 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
|
2832 |
+
6 try:
|
2833 |
+
7 from django.core.management import execute_from_command_line
|
2834 |
+
8 except ImportError as exc:
|
2835 |
+
9 raise ImportError(
|
2836 |
+
10 "Couldn't import Django. Are you sure it's installed and "
|
2837 |
+
11 "available on your PYTHONPATH environment variable? Did you "
|
2838 |
+
12 "forget to activate a virtual environment?"
|
2839 |
+
13 ) from exc
|
2840 |
+
14 execute_from_command_line(sys.argv)
|
2841 |
+
|
2842 |
+
```
|
2843 |
+
|
2844 |
+
================================== Ai Message ==================================
|
2845 |
+
|
2846 |
+
Here is the Unix script that installs dependencies and runs the codebase:
|
2847 |
+
|
2848 |
+
```
|
2849 |
+
python -m venv venv
|
2850 |
+
source venv/bin/activate
|
2851 |
+
pip install -r requirements.txt
|
2852 |
+
python manage.py makemigrations
|
2853 |
+
python manage.py migrate
|
2854 |
+
python manage.py runserver
|
2855 |
+
```
|
2856 |
+
|
2857 |
+
2024-06-10T15:52:49.885372
|
2858 |
+
================================ System Message ================================
|
2859 |
+
|
2860 |
+
You will get information about a codebase that is currently on disk in the current folder.
|
2861 |
+
The user will ask you to write a script that runs the code in a specific way.
|
2862 |
+
You will answer with code blocks that include all the necessary terminal commands.
|
2863 |
+
Do not install globally. Do not use sudo.
|
2864 |
+
Do not explain the code, just give the commands.
|
2865 |
+
Do not use placeholders, use example values (like . for a folder argument) if necessary.
|
2866 |
+
|
2867 |
+
|
2868 |
+
================================ Human Message =================================
|
2869 |
+
|
2870 |
+
|
2871 |
+
Make a unix script that
|
2872 |
+
a) installs dependencies
|
2873 |
+
b) runs all necessary parts of the codebase (in parallel if necessary)
|
2874 |
+
|
2875 |
+
Information about the codebase:
|
2876 |
+
|
2877 |
+
```
|
2878 |
+
File: requirements.txt
|
2879 |
+
1 Django==3.2.5
|
2880 |
+
2 google-api-python-client==2.34.0
|
2881 |
+
3 google-auth-httplib2==0.1.0
|
2882 |
+
4 google-auth-oauthlib==0.5.3
|
2883 |
+
5 pytesseract==0.3.8
|
2884 |
+
6 Pillow==8.3.2
|
2885 |
+
7 gradio==2.9.9
|
2886 |
+
8 plantuml==0.1.5
|
2887 |
+
|
2888 |
+
File: app/controllers/ocr.py
|
2889 |
+
1 import pytesseract
|
2890 |
+
2 from PIL import Image
|
2891 |
+
3 import os
|
2892 |
+
4
|
2893 |
+
5 def ocr_image(image_path):
|
2894 |
+
6 """
|
2895 |
+
7 Extract text from an image using OCR
|
2896 |
+
8 """
|
2897 |
+
9 img = Image.open(image_path)
|
2898 |
+
10 text = pytesseract.image_to_string(img)
|
2899 |
+
11 return text
|
2900 |
+
|
2901 |
+
File: app/controllers/google_ocr.py
|
2902 |
+
1 import os
|
2903 |
+
2 from google.oauth2 import service_account
|
2904 |
+
3 from googleapiclient.discovery import build
|
2905 |
+
4 from googleapiclient.errors import HttpError
|
2906 |
+
5
|
2907 |
+
6 def google_ocr(image_path):
|
2908 |
+
7 """
|
2909 |
+
8 Use Google Apps Script to extract text from an image using OCR
|
2910 |
+
9 """
|
2911 |
+
10 SCOPES = ['https://www.googleapis.com/auth/script.external_request']
|
2912 |
+
11 SERVICE_ACCOUNT_FILE = 'path/to/service_account_key.json'
|
2913 |
+
12
|
2914 |
+
13 credentials = service_account.Credentials.from_service_account_file(
|
2915 |
+
14 SERVICE_ACCOUNT_FILE, SCOPES)
|
2916 |
+
15 service = build('script', 'v1', credentials=credentials)
|
2917 |
+
16
|
2918 |
+
17 with open(image_path, 'rb') as f:
|
2919 |
+
18 image_data = f.read()
|
2920 |
+
19
|
2921 |
+
20 request_body = {
|
2922 |
+
21 'requests': [
|
2923 |
+
22 {
|
2924 |
+
23 'image': {
|
2925 |
+
24 'content': image_data
|
2926 |
+
25 },
|
2927 |
+
26 'features': [
|
2928 |
+
27 {
|
2929 |
+
28 'type': 'TEXT_DETECTION'
|
2930 |
+
29 }
|
2931 |
+
30 ]
|
2932 |
+
31 }
|
2933 |
+
32 ]
|
2934 |
+
33 }
|
2935 |
+
34
|
2936 |
+
35 try:
|
2937 |
+
36 response = service.scripts().run(body=request_body).execute()
|
2938 |
+
37 text = response['responses'][0]['textAnnotations'][0]['description']
|
2939 |
+
38 return text
|
2940 |
+
39 except HttpError as e:
|
2941 |
+
40 print(f'Error: {e}')
|
2942 |
+
41 return None
|
2943 |
+
|
2944 |
+
File: app/controllers/logger.py
|
2945 |
+
1 import logging
|
2946 |
+
2
|
2947 |
+
3 class Logger:
|
2948 |
+
4 def __init__(self):
|
2949 |
+
5 self.logger = logging.getLogger('ocr_logger')
|
2950 |
+
6 self.logger.setLevel(logging.INFO)
|
2951 |
+
7
|
2952 |
+
8 def loggers(self, message):
|
2953 |
+
9 self.logger.info(message)
|
2954 |
+
|
2955 |
+
File: app/views.py
|
2956 |
+
1 from django.shortcuts import HttpResponse
|
2957 |
+
2 from .controllers.ocr import ocr_image
|
2958 |
+
3 from .controllers.google_ocr import google_ocr
|
2959 |
+
4 from .controllers.logger import Logger
|
2960 |
+
5
|
2961 |
+
6 def ocr_view(request):
|
2962 |
+
7 if request.method == 'POST':
|
2963 |
+
8 image = request.FILES['image']
|
2964 |
+
9 image_path = 'path/to/temp/image.jpg'
|
2965 |
+
10 with open(image_path, 'wb+') as f:
|
2966 |
+
11 for chunk in image.chunks():
|
2967 |
+
12 f.write(chunk)
|
2968 |
+
13
|
2969 |
+
14 text = ocr_image(image_path)
|
2970 |
+
15 # Use Google Apps Script OCR as a fallback
|
2971 |
+
16 if not text:
|
2972 |
+
17 text = google_ocr(image_path)
|
2973 |
+
18
|
2974 |
+
19 logger = Logger()
|
2975 |
+
20 logger.loggers(text)
|
2976 |
+
21
|
2977 |
+
22 return HttpResponse(text)
|
2978 |
+
23 return HttpResponse('Invalid request')
|
2979 |
+
|
2980 |
+
File: app/templates/index.html
|
2981 |
+
1 <!DOCTYPE html>
|
2982 |
+
2 <html>
|
2983 |
+
3 <head>
|
2984 |
+
4 <title>OCR App</title>
|
2985 |
+
5 </head>
|
2986 |
+
6 <body>
|
2987 |
+
7 <h1>OCR App</h1>
|
2988 |
+
8 <form method="post" enctype="multipart/form-data">
|
2989 |
+
9 <input type="file" name="image">
|
2990 |
+
10 <button type="submit">Extract Text</button>
|
2991 |
+
11 </form>
|
2992 |
+
12 </body>
|
2993 |
+
13 </html>
|
2994 |
+
|
2995 |
+
File: app/urls.py
|
2996 |
+
1 from django.urls import path
|
2997 |
+
2 from . import views
|
2998 |
+
3
|
2999 |
+
4 urlpatterns = [
|
3000 |
+
5 path('', views.ocr_view, name='ocr_view'),
|
3001 |
+
6 ]
|
3002 |
+
|
3003 |
+
File: app/admin.py
|
3004 |
+
1 from django.contrib import admin
|
3005 |
+
2
|
3006 |
+
3 admin.site.site_header = 'OCR App Admin'
|
3007 |
+
|
3008 |
+
File: app/apps.py
|
3009 |
+
1 from django.apps import AppConfig
|
3010 |
+
2
|
3011 |
+
3 class AppConfig(AppConfig):
|
3012 |
+
4 name = 'app'
|
3013 |
+
5 verbose_name = 'OCR App'
|
3014 |
+
|
3015 |
+
File: manage.py
|
3016 |
+
1 import os
|
3017 |
+
2 import sys
|
3018 |
+
3
|
3019 |
+
4 if __name__ == "__main__":
|
3020 |
+
5 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
|
3021 |
+
6 try:
|
3022 |
+
7 from django.core.management import execute_from_command_line
|
3023 |
+
8 except ImportError as exc:
|
3024 |
+
9 raise ImportError(
|
3025 |
+
10 "Couldn't import Django. Are you sure it's installed and "
|
3026 |
+
11 "available on your PYTHONPATH environment variable? Did you "
|
3027 |
+
12 "forget to activate a virtual environment?"
|
3028 |
+
13 ) from exc
|
3029 |
+
14 execute_from_command_line(sys.argv)
|
3030 |
+
|
3031 |
+
File: project/settings.py
|
3032 |
+
1 INSTALLED_APPS = [
|
3033 |
+
2 'django.contrib.admin',
|
3034 |
+
3 'django.contrib.auth',
|
3035 |
+
4 'django.contrib.contenttypes',
|
3036 |
+
5 'django.contrib.sessions',
|
3037 |
+
6 'django.contrib.messages',
|
3038 |
+
7 'django.contrib.staticfiles',
|
3039 |
+
8 'app',
|
3040 |
+
9 ]
|
3041 |
+
10
|
3042 |
+
11 MIDDLEWARE = [
|
3043 |
+
12 'django.middleware.security.SecurityMiddleware',
|
3044 |
+
13 'django.contrib.sessions.middleware.SessionMiddleware',
|
3045 |
+
14 'django.middleware.common.CommonMiddleware',
|
3046 |
+
15 'django.middleware.csrf.CsrfViewMiddleware',
|
3047 |
+
16 'django.contrib.auth.middleware.AuthenticationMiddleware',
|
3048 |
+
17 'django.contrib.messages.middleware.MessageMiddleware',
|
3049 |
+
18 'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
3050 |
+
19 ]
|
3051 |
+
20
|
3052 |
+
21 ROOT_URLCONF = 'project.urls'
|
3053 |
+
22
|
3054 |
+
23 TEMPLATES = [
|
3055 |
+
24 {
|
3056 |
+
25 'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
3057 |
+
26 'DIRS': [],
|
3058 |
+
27 'APP_DIRS': True,
|
3059 |
+
28 'OPTIONS': {
|
3060 |
+
29 'context_processors': [
|
3061 |
+
30 'django.template.context_processors.debug',
|
3062 |
+
31 'django.template.context_processors.request',
|
3063 |
+
32 'django.contrib.auth.context_processors.auth',
|
3064 |
+
33 'django.contrib.messages.context_processors.messages',
|
3065 |
+
34 ],
|
3066 |
+
35 },
|
3067 |
+
36 },
|
3068 |
+
37 ]
|
3069 |
+
38
|
3070 |
+
39 WSGI_APPLICATION = 'project.wsgi.application'
|
3071 |
+
40
|
3072 |
+
41 DATABASES = {
|
3073 |
+
42 'default': {
|
3074 |
+
43 'ENGINE': 'django.db.backends.sqlite3',
|
3075 |
+
44 'NAME': 'db.sqlite3',
|
3076 |
+
45 }
|
3077 |
+
46 }
|
3078 |
+
47
|
3079 |
+
48 LANGUAGE_CODE = 'en-us'
|
3080 |
+
49
|
3081 |
+
50 TIME_ZONE = 'UTC'
|
3082 |
+
51
|
3083 |
+
52 USE_I18N = True
|
3084 |
+
53
|
3085 |
+
54 USE_L10N = True
|
3086 |
+
55
|
3087 |
+
56 USE_TZ = True
|
3088 |
+
|
3089 |
+
File: project/urls.py
|
3090 |
+
1 from django.contrib import admin
|
3091 |
+
2 from django.urls import include, path
|
3092 |
+
3
|
3093 |
+
4 urlpatterns = [
|
3094 |
+
5 path('admin/', admin.site.urls),
|
3095 |
+
6 path('', include('app.urls')),
|
3096 |
+
7 ]
|
3097 |
+
|
3098 |
+
File: project/wsgi.py
|
3099 |
+
1 import os
|
3100 |
+
2
|
3101 |
+
3 from django.core.wsgi import get_wsgi_application
|
3102 |
+
4
|
3103 |
+
5 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
|
3104 |
+
6
|
3105 |
+
7 application = get_wsgi_application()
|
3106 |
+
|
3107 |
+
```
|
3108 |
+
|
3109 |
+
================================== Ai Message ==================================
|
3110 |
+
|
3111 |
+
Here is the Unix script that installs dependencies and runs the codebase:
|
3112 |
+
|
3113 |
+
```bash
|
3114 |
+
#!/bin/bash
|
3115 |
+
|
3116 |
+
# Install dependencies
|
3117 |
+
python -m pip install -r requirements.txt
|
3118 |
+
|
3119 |
+
# Run the Django development server
|
3120 |
+
python manage.py runserver
|
3121 |
+
```
|
3122 |
+
|
3123 |
+
2024-06-10T15:54:34.735326
|
3124 |
+
================================ System Message ================================
|
3125 |
+
|
3126 |
+
You will get information about a codebase that is currently on disk in the current folder.
|
3127 |
+
The user will ask you to write a script that runs the code in a specific way.
|
3128 |
+
You will answer with code blocks that include all the necessary terminal commands.
|
3129 |
+
Do not install globally. Do not use sudo.
|
3130 |
+
Do not explain the code, just give the commands.
|
3131 |
+
Do not use placeholders, use example values (like . for a folder argument) if necessary.
|
3132 |
+
|
3133 |
+
|
3134 |
+
================================ Human Message =================================
|
3135 |
+
|
3136 |
+
|
3137 |
+
Make a unix script that
|
3138 |
+
a) installs dependencies
|
3139 |
+
b) runs all necessary parts of the codebase (in parallel if necessary)
|
3140 |
+
|
3141 |
+
Information about the codebase:
|
3142 |
+
|
3143 |
+
```
|
3144 |
+
File: Structure
|
3145 |
+
1 project/
|
3146 |
+
2 app/
|
3147 |
+
3 __init__.py
|
3148 |
+
4 models.py
|
3149 |
+
5 views.py
|
3150 |
+
6 templates/
|
3151 |
+
7 base.html
|
3152 |
+
8 index.html
|
3153 |
+
9 __init__.py
|
3154 |
+
10 wsgi.py
|
3155 |
+
11 requirements.txt
|
3156 |
+
12 manage.py
|
3157 |
+
13 README.md
|
3158 |
+
|
3159 |
+
File: requirements.txt
|
3160 |
+
1 Django==3.2.5
|
3161 |
+
2 django-crispy-forms==1.9.2
|
3162 |
+
3 Pillow==8.2.1
|
3163 |
+
|
3164 |
+
File: manage.py
|
3165 |
+
1 import os
|
3166 |
+
2 import sys
|
3167 |
+
3
|
3168 |
+
4 if __name__ == "__main__":
|
3169 |
+
5 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
|
3170 |
+
6 try:
|
3171 |
+
7 from django.core.management import execute_from_command_line
|
3172 |
+
8 except ImportError as exc:
|
3173 |
+
9 raise ImportError(
|
3174 |
+
10 "Couldn't import Django. Are you sure it's installed and "
|
3175 |
+
11 "available on your PYTHONPATH environment variable? Did you "
|
3176 |
+
12 "forget to activate a virtual environment?"
|
3177 |
+
13 ) from exc
|
3178 |
+
14 execute_from_command_line(sys.argv)
|
3179 |
+
|
3180 |
+
File: app/models.py
|
3181 |
+
1 from django.db import models
|
3182 |
+
2
|
3183 |
+
3 class WebSite(models.Model):
|
3184 |
+
4 name = models.CharField(max_length=255)
|
3185 |
+
5 url = models.URLField(unique=True)
|
3186 |
+
6
|
3187 |
+
7 class Product(models.Model):
|
3188 |
+
8 website = models.ForeignKey(WebSite, on_delete=models.CASCADE)
|
3189 |
+
9 name = models.CharField(max_length=255)
|
3190 |
+
10 price = models.DecimalField(max_digits=10, decimal_places=2)
|
3191 |
+
|
3192 |
+
File: app/views.py
|
3193 |
+
1 from django.shortcuts import render
|
3194 |
+
2 from .models import WebSite, Product
|
3195 |
+
3 from .forms import WebSiteForm
|
3196 |
+
4
|
3197 |
+
5 def index(request):
|
3198 |
+
6 websites = WebSite.objects.all()
|
3199 |
+
7 return render(request, 'index.html', {'websites': websites})
|
3200 |
+
8
|
3201 |
+
9 def create_website(request):
|
3202 |
+
10 if request.method == 'POST':
|
3203 |
+
11 form = WebSiteForm(request.POST)
|
3204 |
+
12 if form.is_valid():
|
3205 |
+
13 form.save()
|
3206 |
+
14 return redirect('index')
|
3207 |
+
15 else:
|
3208 |
+
16 form = WebSiteForm()
|
3209 |
+
17 return render(request, 'create_website.html', {'form': form})
|
3210 |
+
18
|
3211 |
+
19 def scrape_website(request, pk):
|
3212 |
+
20 website = WebSite.objects.get(pk=pk)
|
3213 |
+
21 # Scrape website logic here
|
3214 |
+
22 products = []
|
3215 |
+
23 # ...
|
3216 |
+
24 return render(request, 'scrape_result.html', {'products': products})
|
3217 |
+
|
3218 |
+
File: app/templates/base.html
|
3219 |
+
1 <!DOCTYPE html>
|
3220 |
+
2 <html>
|
3221 |
+
3 <head>
|
3222 |
+
4 <title>Web Scraper</title>
|
3223 |
+
5 </head>
|
3224 |
+
6 <body>
|
3225 |
+
7 <div id="content">
|
3226 |
+
8 {% block content %}{% endblock %}
|
3227 |
+
9 </div>
|
3228 |
+
10 </body>
|
3229 |
+
11 </html>
|
3230 |
+
|
3231 |
+
File: app/templates/index.html
|
3232 |
+
1 {% extends 'base.html' %}
|
3233 |
+
2
|
3234 |
+
3 {% block content %}
|
3235 |
+
4 <h1>Websites</h1>
|
3236 |
+
5 <ul>
|
3237 |
+
6 {% for website in websites %}
|
3238 |
+
7 <li><a href="{% url 'scrape_website' website.pk %}">{{ website.name }}</a></li>
|
3239 |
+
8 {% endfor %}
|
3240 |
+
9 </ul>
|
3241 |
+
10 {% endblock %}
|
3242 |
+
|
3243 |
+
File: app/templates/create_website.html
|
3244 |
+
1 {% extends 'base.html' %}
|
3245 |
+
2
|
3246 |
+
3 {% block content %}
|
3247 |
+
4 <h1>Create Website</h1>
|
3248 |
+
5 <form method="post">
|
3249 |
+
6 {% csrf_token %}
|
3250 |
+
7 {{ form.as_p }}
|
3251 |
+
8 <button type="submit">Create</button>
|
3252 |
+
9 </form>
|
3253 |
+
10 {% endblock %}
|
3254 |
+
|
3255 |
+
File: app/templates/scrape_result.html
|
3256 |
+
1 {% extends 'base.html' %}
|
3257 |
+
2
|
3258 |
+
3 {% block content %}
|
3259 |
+
4 <h1>Scrape Result</h1>
|
3260 |
+
5 <ul>
|
3261 |
+
6 {% for product in products %}
|
3262 |
+
7 <li>{{ product.name }} ({{ product.price }})</li>
|
3263 |
+
8 {% endfor %}
|
3264 |
+
9 </ul>
|
3265 |
+
10 {% endblock %}
|
3266 |
+
|
3267 |
+
File: app/forms.py
|
3268 |
+
1 from django import forms
|
3269 |
+
2 from .models import WebSite
|
3270 |
+
3
|
3271 |
+
4 class WebSiteForm(forms.ModelForm):
|
3272 |
+
5 class Meta:
|
3273 |
+
6 model = WebSite
|
3274 |
+
7 fields = ('name', 'url')
|
3275 |
+
|
3276 |
+
```
|
3277 |
+
|
3278 |
+
================================== Ai Message ==================================
|
3279 |
+
|
3280 |
+
Here is the Unix script that installs dependencies and runs the codebase:
|
3281 |
+
|
3282 |
+
```
|
3283 |
+
python -m venv venv
|
3284 |
+
source venv/bin/activate
|
3285 |
+
pip install -r requirements.txt
|
3286 |
+
python manage.py migrate
|
3287 |
+
python manage.py runserver
|
3288 |
+
```
|
3289 |
+
|
3290 |
+
2024-06-10T15:56:25.004838
|
3291 |
+
================================ System Message ================================
|
3292 |
+
|
3293 |
+
You will get information about a codebase that is currently on disk in the current folder.
|
3294 |
+
The user will ask you to write a script that runs the code in a specific way.
|
3295 |
+
You will answer with code blocks that include all the necessary terminal commands.
|
3296 |
+
Do not install globally. Do not use sudo.
|
3297 |
+
Do not explain the code, just give the commands.
|
3298 |
+
Do not use placeholders, use example values (like . for a folder argument) if necessary.
|
3299 |
+
|
3300 |
+
|
3301 |
+
================================ Human Message =================================
|
3302 |
+
|
3303 |
+
|
3304 |
+
Make a unix script that
|
3305 |
+
a) installs dependencies
|
3306 |
+
b) runs all necessary parts of the codebase (in parallel if necessary)
|
3307 |
+
|
3308 |
+
Information about the codebase:
|
3309 |
+
|
3310 |
+
```
|
3311 |
+
File: Structure
|
3312 |
+
1 project/
|
3313 |
+
2 app/
|
3314 |
+
3 __init__.py
|
3315 |
+
4 models.py
|
3316 |
+
5 views.py
|
3317 |
+
6 urls.py
|
3318 |
+
7 templates/
|
3319 |
+
8 base.html
|
3320 |
+
9 index.html
|
3321 |
+
10 static/
|
3322 |
+
11 css/
|
3323 |
+
12 style.css
|
3324 |
+
13 js/
|
3325 |
+
14 script.js
|
3326 |
+
15 __init__.py
|
3327 |
+
16 manage.py
|
3328 |
+
17 requirements.txt
|
3329 |
+
|
3330 |
+
File: requirements.txt
|
3331 |
+
1 Django==3.2.5
|
3332 |
+
2 requests==2.25.1
|
3333 |
+
3 beautifulsoup4==4.9.3
|
3334 |
+
4 selenium==3.141.0
|
3335 |
+
|
3336 |
+
File: app/models.py
|
3337 |
+
1 from django.db import models
|
3338 |
+
2
|
3339 |
+
3 class WebSite(models.Model):
|
3340 |
+
4 name = models.CharField(max_length=255)
|
3341 |
+
5 url = models.URLField(unique=True)
|
3342 |
+
6
|
3343 |
+
7 class Product(models.Model):
|
3344 |
+
8 website = models.ForeignKey(WebSite, on_delete=models.CASCADE)
|
3345 |
+
9 name = models.CharField(max_length=255)
|
3346 |
+
10 price = models.DecimalField(max_digits=10, decimal_places=2)
|
3347 |
+
|
3348 |
+
File: app/views.py
|
3349 |
+
1 from django.shortcuts import render
|
3350 |
+
2 from .models import WebSite, Product
|
3351 |
+
3 from bs4 import BeautifulSoup
|
3352 |
+
4 from selenium import webdriver
|
3353 |
+
5 import requests
|
3354 |
+
6
|
3355 |
+
7 def index(request):
|
3356 |
+
8 websites = WebSite.objects.all()
|
3357 |
+
9 return render(request, 'index.html', {'websites': websites})
|
3358 |
+
10
|
3359 |
+
11 def scrape_website(request, pk):
|
3360 |
+
12 website = WebSite.objects.get(pk=pk)
|
3361 |
+
13 url = website.url
|
3362 |
+
14 response = requests.get(url)
|
3363 |
+
15 soup = BeautifulSoup(response.content, 'html.parser')
|
3364 |
+
16 products = []
|
3365 |
+
17 for product in soup.find_all('div', {'class': 'product'}):
|
3366 |
+
18 name = product.find('h2').text.strip()
|
3367 |
+
19 price = product.find('span', {'class': 'price'}).text.strip()
|
3368 |
+
20 product_obj = Product(website=website, name=name, price=price)
|
3369 |
+
21 products.append(product_obj)
|
3370 |
+
22 Product.objects.bulk_create(products)
|
3371 |
+
23 return render(request, 'index.html', {'websites': [website]})
|
3372 |
+
24
|
3373 |
+
25 def create_specification(request, pk):
|
3374 |
+
26 website = WebSite.objects.get(pk=pk)
|
3375 |
+
27 url = website.url
|
3376 |
+
28 response = requests.get(url)
|
3377 |
+
29 soup = BeautifulSoup(response.content, 'html.parser')
|
3378 |
+
30 specification = []
|
3379 |
+
31 for spec in soup.find_all('table', {'class': 'specification'}):
|
3380 |
+
32 rows = spec.find_all('tr')
|
3381 |
+
33 for row in rows:
|
3382 |
+
34 key = row.find('th').text.strip()
|
3383 |
+
35 value = row.find('td').text.strip()
|
3384 |
+
36 specification.append({key: value})
|
3385 |
+
37 return render(request, 'specification.html', {'specification': specification})
|
3386 |
+
|
3387 |
+
File: app/urls.py
|
3388 |
+
1 from django.urls import path
|
3389 |
+
2 from . import views
|
3390 |
+
3
|
3391 |
+
4 urlpatterns = [
|
3392 |
+
5 path('', views.index, name='index'),
|
3393 |
+
6 path('scrape/<pk>/', views.scrape_website, name='scrape_website'),
|
3394 |
+
7 path('specification/<pk>/', views.create_specification, name='create_specification'),
|
3395 |
+
8 ]
|
3396 |
+
|
3397 |
+
File: templates/base.html
|
3398 |
+
1 <!DOCTYPE html>
|
3399 |
+
2 <html>
|
3400 |
+
3 <head>
|
3401 |
+
4 <title>Web Scraping</title>
|
3402 |
+
5 <link rel="stylesheet" href="{% static 'css/style.css' %}">
|
3403 |
+
6 </head>
|
3404 |
+
7 <body>
|
3405 |
+
8 <header>
|
3406 |
+
9 <nav>
|
3407 |
+
10 <ul>
|
3408 |
+
11 {% for website in websites %}
|
3409 |
+
12 <li><a href="{% url 'scrape_website' website.pk %}">{{ website.name }}</a></li>
|
3410 |
+
13 {% endfor %}
|
3411 |
+
14 </ul>
|
3412 |
+
15 </nav>
|
3413 |
+
16 </header>
|
3414 |
+
17 <main>
|
3415 |
+
18 {% block content %}{% endblock %}
|
3416 |
+
19 </main>
|
3417 |
+
20 </body>
|
3418 |
+
21 </html>
|
3419 |
+
|
3420 |
+
File: templates/index.html
|
3421 |
+
1 {% extends 'base.html' %}
|
3422 |
+
2
|
3423 |
+
3 {% block content %}
|
3424 |
+
4 <h1>Websites</h1>
|
3425 |
+
5 <ul>
|
3426 |
+
6 {% for website in websites %}
|
3427 |
+
7 <li>{{ website.name }} ({{ website.url }})</li>
|
3428 |
+
8 {% endfor %}
|
3429 |
+
9 </ul>
|
3430 |
+
10 {% endblock %}
|
3431 |
+
|
3432 |
+
File: templates/specification.html
|
3433 |
+
1 {% extends 'base.html' %}
|
3434 |
+
2
|
3435 |
+
3 {% block content %}
|
3436 |
+
4 <h1>Specification</h1>
|
3437 |
+
5 <table>
|
3438 |
+
6 <tr>
|
3439 |
+
7 <th>Key</th>
|
3440 |
+
8 <th>Value</th>
|
3441 |
+
9 </tr>
|
3442 |
+
10 {% for spec in specification %}
|
3443 |
+
11 <tr>
|
3444 |
+
12 <td>{{ spec.key }}</td>
|
3445 |
+
13 <td>{{ spec.value }}</td>
|
3446 |
+
14 </tr>
|
3447 |
+
15 {% endfor %}
|
3448 |
+
16 </table>
|
3449 |
+
17 {% endblock %}
|
3450 |
+
|
3451 |
+
File: static/css/style.css
|
3452 |
+
1 body {
|
3453 |
+
2 font-family: Arial, sans-serif;
|
3454 |
+
3 }
|
3455 |
+
4
|
3456 |
+
5 header {
|
3457 |
+
6 background-color: #f0f0f0;
|
3458 |
+
7 padding: 20px;
|
3459 |
+
8 text-align: center;
|
3460 |
+
9 }
|
3461 |
+
10
|
3462 |
+
11 nav ul {
|
3463 |
+
12 list-style: none;
|
3464 |
+
13 margin: 0;
|
3465 |
+
14 padding: 0;
|
3466 |
+
15 }
|
3467 |
+
16
|
3468 |
+
17 nav li {
|
3469 |
+
18 display: inline-block;
|
3470 |
+
19 margin-right: 20px;
|
3471 |
+
20 }
|
3472 |
+
21
|
3473 |
+
22 nav a {
|
3474 |
+
23 color: #337ab7;
|
3475 |
+
24 text-decoration: none;
|
3476 |
+
25 }
|
3477 |
+
26
|
3478 |
+
27 nav a:hover {
|
3479 |
+
28 color: #23527c;
|
3480 |
+
29 }
|
3481 |
+
30
|
3482 |
+
31 main {
|
3483 |
+
32 display: flex;
|
3484 |
+
33 flex-direction: column;
|
3485 |
+
34 align-items: center;
|
3486 |
+
35 padding: 20px;
|
3487 |
+
36 }
|
3488 |
+
37
|
3489 |
+
38 table {
|
3490 |
+
39 border-collapse: collapse;
|
3491 |
+
40 width: 100%;
|
3492 |
+
41 }
|
3493 |
+
42
|
3494 |
+
43 th, td {
|
3495 |
+
44 border: 1px solid #ddd;
|
3496 |
+
45 padding: 10px;
|
3497 |
+
46 text-align: left;
|
3498 |
+
47 }
|
3499 |
+
48
|
3500 |
+
49 th {
|
3501 |
+
50 background-color: #f0f0f0;
|
3502 |
+
51 }
|
3503 |
+
|
3504 |
+
File: manage.py
|
3505 |
+
1 import os
|
3506 |
+
2 import sys
|
3507 |
+
3
|
3508 |
+
4 if __name__ == "__main__":
|
3509 |
+
5 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
|
3510 |
+
6 try:
|
3511 |
+
7 from django.core.management import execute_from_command_line
|
3512 |
+
8 except ImportError as exc:
|
3513 |
+
9 raise ImportError(
|
3514 |
+
10 "Couldn't import Django. Are you sure it's installed and "
|
3515 |
+
11 "available on your PYTHONPATH environment variable? Did you "
|
3516 |
+
12 "forget to activate a virtual environment?"
|
3517 |
+
13 ) from exc
|
3518 |
+
14 execute_from_command_line(sys.argv)
|
3519 |
+
|
3520 |
+
File: commands
|
3521 |
+
1 python manage.py makemigrations
|
3522 |
+
2 python manage.py migrate
|
3523 |
+
3 python manage.py runserver
|
3524 |
+
|
3525 |
+
```
|
3526 |
+
|
3527 |
+
================================== Ai Message ==================================
|
3528 |
+
|
3529 |
+
Here is the Unix script that installs dependencies and runs the codebase:
|
3530 |
+
```
|
3531 |
+
#!/bin/bash
|
3532 |
+
|
3533 |
+
# Install dependencies
|
3534 |
+
pip install -r requirements.txt
|
3535 |
+
|
3536 |
+
# Run migrations
|
3537 |
+
python manage.py makemigrations
|
3538 |
+
python manage.py migrate
|
3539 |
+
|
3540 |
+
# Run the development server
|
3541 |
+
python manage.py runserver
|
3542 |
+
```
|
3543 |
+
Save this script to a file (e.g. `run.sh`), make it executable with `chmod +x run.sh`, and then run it with `./run.sh`.
|
3544 |
+
|
3545 |
+
2024-06-10T20:14:34.164304
|
3546 |
+
================================ System Message ================================
|
3547 |
+
|
3548 |
+
You will get information about a codebase that is currently on disk in the current folder.
|
3549 |
+
The user will ask you to write a script that runs the code in a specific way.
|
3550 |
+
You will answer with code blocks that include all the necessary terminal commands.
|
3551 |
+
Do not install globally. Do not use sudo.
|
3552 |
+
Do not explain the code, just give the commands.
|
3553 |
+
Do not use placeholders, use example values (like . for a folder argument) if necessary.
|
3554 |
+
|
3555 |
+
|
3556 |
+
================================ Human Message =================================
|
3557 |
+
|
3558 |
+
|
3559 |
+
Make a unix script that
|
3560 |
+
a) installs dependencies
|
3561 |
+
b) runs all necessary parts of the codebase (in parallel if necessary)
|
3562 |
+
|
3563 |
+
Information about the codebase:
|
3564 |
+
|
3565 |
+
```
|
3566 |
+
File: Structure
|
3567 |
+
1 project/
|
3568 |
+
2 app/
|
3569 |
+
3 __init__.py
|
3570 |
+
4 models.py
|
3571 |
+
5 views.py
|
3572 |
+
6 templates/
|
3573 |
+
7 base.html
|
3574 |
+
8 index.html
|
3575 |
+
9 __init__.py
|
3576 |
+
10 urls.py
|
3577 |
+
11 __pycache__/
|
3578 |
+
12 manage.py
|
3579 |
+
13 requirements.txt
|
3580 |
+
14 README.md
|
3581 |
+
|
3582 |
+
File: manage.py
|
3583 |
+
1 ```
|
3584 |
+
2 **app/__init__.py**
|
3585 |
+
|
3586 |
+
File: app/models.py
|
3587 |
+
1 from django.db import models
|
3588 |
+
2
|
3589 |
+
3 class WebSite(models.Model):
|
3590 |
+
4 name = models.CharField(max_length=255)
|
3591 |
+
5 url = models.URLField(max_length=255)
|
3592 |
+
6
|
3593 |
+
7 class Product(models.Model):
|
3594 |
+
8 website = models.ForeignKey(WebSite, on_delete=models.CASCADE)
|
3595 |
+
9 name = models.CharField(max_length=255)
|
3596 |
+
10 price = models.DecimalField(max_digits=10, decimal_places=2)
|
3597 |
+
|
3598 |
+
File: app/views.py
|
3599 |
+
1 from django.shortcuts import render
|
3600 |
+
2 from .models import WebSite, Product
|
3601 |
+
3 from django.http import HttpResponse
|
3602 |
+
4 import xlsxwriter
|
3603 |
+
5
|
3604 |
+
6 def index(request):
|
3605 |
+
7 websites = WebSite.objects.all()
|
3606 |
+
8 return render(request, 'index.html', {'websites': websites})
|
3607 |
+
9
|
3608 |
+
10 def scrape_website(request, pk):
|
3609 |
+
11 website = WebSite.objects.get(pk=pk)
|
3610 |
+
12 products = Product.objects.filter(website=website)
|
3611 |
+
13 response = HttpResponse(content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
|
3612 |
+
14 response['Content-Disposition'] = 'attachment; filename="products.xlsx"'
|
3613 |
+
15 workbook = xlsxwriter.Workbook(response, {'in_memory': True})
|
3614 |
+
16 worksheet = workbook.add_worksheet()
|
3615 |
+
17 worksheet.write(0, 0, 'Name')
|
3616 |
+
18 worksheet.write(0, 1, 'Price')
|
3617 |
+
19 row = 1
|
3618 |
+
20 for product in products:
|
3619 |
+
21 worksheet.write(row, 0, product.name)
|
3620 |
+
22 worksheet.write(row, 1, product.price)
|
3621 |
+
23 row += 1
|
3622 |
+
24 workbook.close()
|
3623 |
+
25 return response
|
3624 |
+
|
3625 |
+
File: app/templates/base.html
|
3626 |
+
1 <!DOCTYPE html>
|
3627 |
+
2 <html>
|
3628 |
+
3 <head>
|
3629 |
+
4 <title>Web Scraping</title>
|
3630 |
+
5 </head>
|
3631 |
+
6 <body>
|
3632 |
+
7 <h1>Web Scraping</h1>
|
3633 |
+
8 <ul>
|
3634 |
+
9 {% for website in websites %}
|
3635 |
+
10 <li><a href="{% url 'scrape_website' website.pk %}">{{ website.name }}</a></li>
|
3636 |
+
11 {% endfor %}
|
3637 |
+
12 </ul>
|
3638 |
+
13 </body>
|
3639 |
+
14 </html>
|
3640 |
+
|
3641 |
+
File: app/templates/index.html
|
3642 |
+
1 {% extends 'base.html' %}
|
3643 |
+
|
3644 |
+
File: app/urls.py
|
3645 |
+
1 from django.urls import path
|
3646 |
+
2 from . import views
|
3647 |
+
3
|
3648 |
+
4 urlpatterns = [
|
3649 |
+
5 path('', views.index, name='index'),
|
3650 |
+
6 path('scrape/<pk>/', views.scrape_website, name='scrape_website'),
|
3651 |
+
7 ]
|
3652 |
+
|
3653 |
+
File: requirements.txt
|
3654 |
+
1 Django==3.2.5
|
3655 |
+
2 xlsxwriter==1.4.4
|
3656 |
+
|
3657 |
+
```
|
3658 |
+
|
3659 |
+
================================== Ai Message ==================================
|
3660 |
+
|
3661 |
+
Here is the Unix script that installs dependencies and runs the codebase:
|
3662 |
+
```
|
3663 |
+
#!/bin/bash
|
3664 |
+
|
3665 |
+
# Install dependencies
|
3666 |
+
pip install -r requirements.txt
|
3667 |
+
|
3668 |
+
# Run the Django development server
|
3669 |
+
python manage.py runserver
|
3670 |
+
```
|
3671 |
+
|
3672 |
+
2024-06-10T20:15:02.393070
|
3673 |
+
================================ System Message ================================
|
3674 |
+
|
3675 |
+
You will get information about a codebase that is currently on disk in the current folder.
|
3676 |
+
The user will ask you to write a script that runs the code in a specific way.
|
3677 |
+
You will answer with code blocks that include all the necessary terminal commands.
|
3678 |
+
Do not install globally. Do not use sudo.
|
3679 |
+
Do not explain the code, just give the commands.
|
3680 |
+
Do not use placeholders, use example values (like . for a folder argument) if necessary.
|
3681 |
+
|
3682 |
+
|
3683 |
+
================================ Human Message =================================
|
3684 |
+
|
3685 |
+
|
3686 |
+
Make a unix script that
|
3687 |
+
a) installs dependencies
|
3688 |
+
b) runs all necessary parts of the codebase (in parallel if necessary)
|
3689 |
+
|
3690 |
+
Information about the codebase:
|
3691 |
+
|
3692 |
+
```
|
3693 |
+
File: Structure
|
3694 |
+
1 project/
|
3695 |
+
2 project/
|
3696 |
+
3 settings.py
|
3697 |
+
4 urls.py
|
3698 |
+
5 wsgi.py
|
3699 |
+
6 app/
|
3700 |
+
7 models.py
|
3701 |
+
8 views.py
|
3702 |
+
9 templates/
|
3703 |
+
10 base.html
|
3704 |
+
11 index.html
|
3705 |
+
12 __init__.py
|
3706 |
+
13 requirements.txt
|
3707 |
+
14 manage.py
|
3708 |
+
|
3709 |
+
File: requirements.txt
|
3710 |
+
1 Django==3.2.5
|
3711 |
+
2 requests==2.25.1
|
3712 |
+
3 beautifulsoup4==4.9.3
|
3713 |
+
4 selenium==3.141.0
|
3714 |
+
|
3715 |
+
File: project/settings.py
|
3716 |
+
1 INSTALLED_APPS = [
|
3717 |
+
2 'django.contrib.admin',
|
3718 |
+
3 'django.contrib.auth',
|
3719 |
+
4 'django.contrib.contenttypes',
|
3720 |
+
5 'django.contrib.sessions',
|
3721 |
+
6 'django.contrib.messages',
|
3722 |
+
7 'django.contrib.staticfiles',
|
3723 |
+
8 'app',
|
3724 |
+
9 ]
|
3725 |
+
10
|
3726 |
+
11 DATABASES = {
|
3727 |
+
12 'default': {
|
3728 |
+
13 'ENGINE': 'django.db.backends.sqlite3',
|
3729 |
+
14 'NAME': BASE_DIR / 'db.sqlite3',
|
3730 |
+
15 }
|
3731 |
+
16 }
|
3732 |
+
17
|
3733 |
+
18 STATIC_URL = '/static/'
|
3734 |
+
|
3735 |
+
File: app/models.py
|
3736 |
+
1 from django.db import models
|
3737 |
+
2
|
3738 |
+
3 class WebSite(models.Model):
|
3739 |
+
4 url = models.URLField(unique=True)
|
3740 |
+
5 data = models.TextField(blank=True)
|
3741 |
+
6
|
3742 |
+
7 def __str__(self):
|
3743 |
+
8 return self.url
|
3744 |
+
|
3745 |
+
File: app/views.py
|
3746 |
+
1 from django.shortcuts import render
|
3747 |
+
2 from .models import WebSite
|
3748 |
+
3 from bs4 import BeautifulSoup
|
3749 |
+
4 from selenium import webdriver
|
3750 |
+
5 import requests
|
3751 |
+
6
|
3752 |
+
7 def index(request):
|
3753 |
+
8 websites = WebSite.objects.all()
|
3754 |
+
9 return render(request, 'index.html', {'websites': websites})
|
3755 |
+
10
|
3756 |
+
11 def scrape_website(request, pk):
|
3757 |
+
12 website = WebSite.objects.get(pk=pk)
|
3758 |
+
13 url = website.url
|
3759 |
+
14 response = requests.get(url)
|
3760 |
+
15 soup = BeautifulSoup(response.content, 'html.parser')
|
3761 |
+
16 data = ''
|
3762 |
+
17 for item in soup.find_all('div'):
|
3763 |
+
18 data += item.text + '\n'
|
3764 |
+
19 website.data = data
|
3765 |
+
20 website.save()
|
3766 |
+
21 return render(request, 'base.html', {'data': data})
|
3767 |
+
|
3768 |
+
File: app/templates/base.html
|
3769 |
+
1 <!DOCTYPE html>
|
3770 |
+
2 <html>
|
3771 |
+
3 <head>
|
3772 |
+
4 <title>Scraped Data</title>
|
3773 |
+
5 </head>
|
3774 |
+
6 <body>
|
3775 |
+
7 <h1>Scraped Data</h1>
|
3776 |
+
8 <pre>{{ data }}</pre>
|
3777 |
+
9 </body>
|
3778 |
+
10 </html>
|
3779 |
+
|
3780 |
+
File: app/templates/index.html
|
3781 |
+
1 <!DOCTYPE html>
|
3782 |
+
2 <html>
|
3783 |
+
3 <head>
|
3784 |
+
4 <title>Websites</title>
|
3785 |
+
5 </head>
|
3786 |
+
6 <body>
|
3787 |
+
7 <h1>Websites</h1>
|
3788 |
+
8 <ul>
|
3789 |
+
9 {% for website in websites %}
|
3790 |
+
10 <li><a href="{% url 'scrape_website' website.pk %}">{{ website.url }}</a></li>
|
3791 |
+
11 {% empty %}
|
3792 |
+
12 <li>No websites available.</li>
|
3793 |
+
13 {% endfor %}
|
3794 |
+
14 </ul>
|
3795 |
+
15 </body>
|
3796 |
+
16 </html>
|
3797 |
+
|
3798 |
+
File: project/urls.py
|
3799 |
+
1 from django.urls import path, include
|
3800 |
+
2 from . import views
|
3801 |
+
3
|
3802 |
+
4 urlpatterns = [
|
3803 |
+
5 path('admin/', admin.site.urls),
|
3804 |
+
6 path('', views.index, name='index'),
|
3805 |
+
7 path('scrape/<pk>/', views.scrape_website, name='scrape_website'),
|
3806 |
+
8 ]
|
3807 |
+
|
3808 |
+
File: manage.py
|
3809 |
+
1 #!/usr/bin/env python
|
3810 |
+
2 import os
|
3811 |
+
3 import sys
|
3812 |
+
4
|
3813 |
+
5 if __name__ == "__main__":
|
3814 |
+
6 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
|
3815 |
+
7 try:
|
3816 |
+
8 from django.core.management import execute_from_command_line
|
3817 |
+
9 except ImportError as exc:
|
3818 |
+
10 raise ImportError(
|
3819 |
+
11 "Couldn't import Django. Are you sure it's installed and "
|
3820 |
+
12 "available on your PYTHONPATH environment variable? Did you "
|
3821 |
+
13 "forget to activate a virtual environment?"
|
3822 |
+
14 ) from exc
|
3823 |
+
15 execute_from_command_line(sys.argv)
|
3824 |
+
|
3825 |
+
```
|
3826 |
+
|
3827 |
+
================================== Ai Message ==================================
|
3828 |
+
|
3829 |
+
Here is the Unix script that installs dependencies and runs the codebase:
|
3830 |
+
|
3831 |
+
```
|
3832 |
+
python -m venv venv
|
3833 |
+
source venv/bin/activate
|
3834 |
+
pip install -r requirements.txt
|
3835 |
+
python manage.py makemigrations
|
3836 |
+
python manage.py migrate
|
3837 |
+
python manage.py runserver
|
3838 |
+
```
|
3839 |
+
|
3840 |
+
2024-06-10T20:16:00.251227
|
3841 |
+
================================ System Message ================================
|
3842 |
+
|
3843 |
+
You will get information about a codebase that is currently on disk in the current folder.
|
3844 |
+
The user will ask you to write a script that runs the code in a specific way.
|
3845 |
+
You will answer with code blocks that include all the necessary terminal commands.
|
3846 |
+
Do not install globally. Do not use sudo.
|
3847 |
+
Do not explain the code, just give the commands.
|
3848 |
+
Do not use placeholders, use example values (like . for a folder argument) if necessary.
|
3849 |
+
|
3850 |
+
|
3851 |
+
================================ Human Message =================================
|
3852 |
+
|
3853 |
+
|
3854 |
+
Make a unix script that
|
3855 |
+
a) installs dependencies
|
3856 |
+
b) runs all necessary parts of the codebase (in parallel if necessary)
|
3857 |
+
|
3858 |
+
Information about the codebase:
|
3859 |
+
|
3860 |
+
```
|
3861 |
+
File: Structure
|
3862 |
+
1 project/
|
3863 |
+
2 project/
|
3864 |
+
3 settings.py
|
3865 |
+
4 urls.py
|
3866 |
+
5 wsgi.py
|
3867 |
+
6 app/
|
3868 |
+
7 models.py
|
3869 |
+
8 views.py
|
3870 |
+
9 templates/
|
3871 |
+
10 base.html
|
3872 |
+
11 index.html
|
3873 |
+
12 __init__.py
|
3874 |
+
13 __pycache__/
|
3875 |
+
14 requirements.txt
|
3876 |
+
15 manage.py
|
3877 |
+
|
3878 |
+
File: requirements.txt
|
3879 |
+
1 Django==3.2.5
|
3880 |
+
2 python-decouple==3.4
|
3881 |
+
|
3882 |
+
File: project/settings.py
|
3883 |
+
1 import os
|
3884 |
+
2 from decouple import config
|
3885 |
+
3
|
3886 |
+
4 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
3887 |
+
5
|
3888 |
+
6 SECRET_KEY = config('SECRET_KEY')
|
3889 |
+
7
|
3890 |
+
8 DEBUG = True
|
3891 |
+
9
|
3892 |
+
10 ALLOWED_HOSTS = []
|
3893 |
+
11
|
3894 |
+
12 INSTALLED_APPS = [
|
3895 |
+
13 'django.contrib.admin',
|
3896 |
+
14 'django.contrib.auth',
|
3897 |
+
15 'django.contrib.contenttypes',
|
3898 |
+
16 'django.contrib.sessions',
|
3899 |
+
17 'django.contrib.messages',
|
3900 |
+
18 'django.contrib.staticfiles',
|
3901 |
+
19 'app',
|
3902 |
+
20 ]
|
3903 |
+
21
|
3904 |
+
22 MIDDLEWARE = [
|
3905 |
+
23 'django.middleware.security.SecurityMiddleware',
|
3906 |
+
24 'django.contrib.sessions.middleware.SessionMiddleware',
|
3907 |
+
25 'django.middleware.common.CommonMiddleware',
|
3908 |
+
26 'django.middleware.csrf.CsrfViewMiddleware',
|
3909 |
+
27 'django.contrib.auth.middleware.AuthenticationMiddleware',
|
3910 |
+
28 'django.contrib.messages.middleware.MessageMiddleware',
|
3911 |
+
29 'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
3912 |
+
30 ]
|
3913 |
+
31
|
3914 |
+
32 ROOT_URLCONF = 'project.urls'
|
3915 |
+
33
|
3916 |
+
34 TEMPLATES = [
|
3917 |
+
35 {
|
3918 |
+
36 'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
3919 |
+
37 'DIRS': [os.path.join(BASE_DIR, 'templates')],
|
3920 |
+
38 'APP_DIRS': True,
|
3921 |
+
39 'OPTIONS': {
|
3922 |
+
40 'context_processors': [
|
3923 |
+
41 'django.template.context_processors.debug',
|
3924 |
+
42 'django.template.context_processors.request',
|
3925 |
+
43 'django.contrib.auth.context_processors.auth',
|
3926 |
+
44 'django.contrib.messages.context_processors.messages',
|
3927 |
+
45 ],
|
3928 |
+
46 },
|
3929 |
+
47 },
|
3930 |
+
48 ]
|
3931 |
+
49
|
3932 |
+
50 WSGI_APPLICATION = 'project.wsgi.application'
|
3933 |
+
51
|
3934 |
+
52 DATABASES = {
|
3935 |
+
53 'default': {
|
3936 |
+
54 'ENGINE': 'django.db.backends.sqlite3',
|
3937 |
+
55 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
3938 |
+
56 }
|
3939 |
+
57 }
|
3940 |
+
58
|
3941 |
+
59 LANGUAGE_CODE = 'en-us'
|
3942 |
+
60
|
3943 |
+
61 TIME_ZONE = 'UTC'
|
3944 |
+
62
|
3945 |
+
63 USE_I18N = True
|
3946 |
+
64
|
3947 |
+
65 USE_L10N = True
|
3948 |
+
66
|
3949 |
+
67 USE_TZ = True
|
3950 |
+
68
|
3951 |
+
69 STATIC_URL = '/static/'
|
3952 |
+
|
3953 |
+
File: project/urls.py
|
3954 |
+
1 from django.contrib import admin
|
3955 |
+
2 from django.urls import path, include
|
3956 |
+
3
|
3957 |
+
4 urlpatterns = [
|
3958 |
+
5 path('admin/', admin.site.urls),
|
3959 |
+
6 path('', include('app.urls')),
|
3960 |
+
7 ]
|
3961 |
+
|
3962 |
+
File: app/models.py
|
3963 |
+
1 from django.db import models
|
3964 |
+
2
|
3965 |
+
3 class WebSite(models.Model):
|
3966 |
+
4 name = models.CharField(max_length=255)
|
3967 |
+
5 url = models.URLField(max_length=255)
|
3968 |
+
6
|
3969 |
+
7 def __str__(self):
|
3970 |
+
8 return self.name
|
3971 |
+
|
3972 |
+
File: app/views.py
|
3973 |
+
1 from django.shortcuts import render
|
3974 |
+
2 from .models import WebSite
|
3975 |
+
3
|
3976 |
+
4 def index(request):
|
3977 |
+
5 websites = WebSite.objects.all()
|
3978 |
+
6 return render(request, 'index.html', {'websites': websites})
|
3979 |
+
|
3980 |
+
File: app/templates/base.html
|
3981 |
+
1 <!DOCTYPE html>
|
3982 |
+
2 <html>
|
3983 |
+
3 <head>
|
3984 |
+
4 <title>Web Scraping App</title>
|
3985 |
+
5 </head>
|
3986 |
+
6 <body>
|
3987 |
+
7 <h1>Web Scraping App</h1>
|
3988 |
+
8 <div id="content">
|
3989 |
+
9 {% block content %}{% endblock %}
|
3990 |
+
10 </div>
|
3991 |
+
11 </body>
|
3992 |
+
12 </html>
|
3993 |
+
|
3994 |
+
File: app/templates/index.html
|
3995 |
+
1 {% extends 'base.html' %}
|
3996 |
+
2
|
3997 |
+
3 {% block content %}
|
3998 |
+
4 <h2>Websites</h2>
|
3999 |
+
5 <ul>
|
4000 |
+
6 {% for website in websites %}
|
4001 |
+
7 <li>{{ website.name }} ({{ website.url }})</li>
|
4002 |
+
8 {% empty %}
|
4003 |
+
9 <li>No websites available.</li>
|
4004 |
+
10 {% endfor %}
|
4005 |
+
11 </ul>
|
4006 |
+
12 {% endblock %}
|
4007 |
+
|
4008 |
+
File: app/urls.py
|
4009 |
+
1 from django.urls import path
|
4010 |
+
2 from . import views
|
4011 |
+
3
|
4012 |
+
4 urlpatterns = [
|
4013 |
+
5 path('', views.index, name='index'),
|
4014 |
+
6 ]
|
4015 |
+
|
4016 |
+
File: manage.py
|
4017 |
+
1 #!/usr/bin/env python
|
4018 |
+
2 import os
|
4019 |
+
3 import sys
|
4020 |
+
4
|
4021 |
+
5 if __name__ == "__main__":
|
4022 |
+
6 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
|
4023 |
+
7 try:
|
4024 |
+
8 from django.core.management import execute_from_command_line
|
4025 |
+
9 except ImportError as exc:
|
4026 |
+
10 raise ImportError(
|
4027 |
+
11 "Couldn't import Django. Are you sure it's installed and "
|
4028 |
+
12 "available on your PYTHONPATH environment variable? Did you "
|
4029 |
+
13 "forget to activate a virtual environment?"
|
4030 |
+
14 ) from exc
|
4031 |
+
15 execute_from_command_line(sys.argv)
|
4032 |
+
|
4033 |
+
File: command
|
4034 |
+
1 python manage.py runserver
|
4035 |
+
|
4036 |
+
```
|
4037 |
+
|
4038 |
+
================================== Ai Message ==================================
|
4039 |
+
|
4040 |
+
Here is the Unix script that installs dependencies and runs the codebase:
|
4041 |
+
|
4042 |
+
```
|
4043 |
+
#!/bin/bash
|
4044 |
+
|
4045 |
+
# Install dependencies
|
4046 |
+
pip install -r requirements.txt
|
4047 |
+
|
4048 |
+
# Run the Django development server
|
4049 |
+
python manage.py runserver
|
4050 |
+
```
|
controllers/ai/Structure
CHANGED
@@ -1,16 +1,15 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
requirements.txt
|
|
|
1 |
+
project/
|
2 |
+
project/
|
3 |
+
settings.py
|
4 |
+
urls.py
|
5 |
+
wsgi.py
|
6 |
+
app/
|
7 |
+
models.py
|
8 |
+
views.py
|
9 |
+
templates/
|
10 |
+
base.html
|
11 |
+
index.html
|
12 |
+
__init__.py
|
13 |
+
__pycache__/
|
14 |
+
requirements.txt
|
15 |
+
manage.py
|
|
controllers/ai/app.py
CHANGED
@@ -1,43 +1,26 @@
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
-
import gradio as gr
|
3 |
import pytesseract
|
4 |
-
from
|
5 |
-
|
|
|
6 |
|
7 |
app = Flask(__name__)
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
-
SERVICE_ACCOUNT_FILE = 'service_account_key.json'
|
12 |
-
|
13 |
-
# Load credentials from service account file
|
14 |
-
creds = service_account.Credentials.from_service_account_file(
|
15 |
-
SERVICE_ACCOUNT_FILE, SCOPES=SCOPES)
|
16 |
-
|
17 |
-
# Create Google Apps Script API client
|
18 |
-
script_service = build('script', 'v1', credentials=creds)
|
19 |
-
|
20 |
-
# Create Gradio interface
|
21 |
-
iface = gr.Interface(
|
22 |
-
fn=lambda img: ocr(img),
|
23 |
-
inputs="image",
|
24 |
-
outputs="text",
|
25 |
-
title="OCR App",
|
26 |
-
description="Upload an image to extract text"
|
27 |
-
)
|
28 |
|
29 |
@app.route('/ocr', methods=['POST'])
|
30 |
-
def ocr(
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
40 |
|
41 |
if __name__ == '__main__':
|
42 |
-
iface.launch()
|
43 |
app.run(debug=True)
|
|
|
1 |
from flask import Flask, request, jsonify
|
|
|
2 |
import pytesseract
|
3 |
+
from PIL import Image
|
4 |
+
import gradio as gr
|
5 |
+
from plantuml import PlantUML
|
6 |
|
7 |
app = Flask(__name__)
|
8 |
|
9 |
+
# Initialize PlantUML
|
10 |
+
plantuml = PlantUML()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
@app.route('/ocr', methods=['POST'])
|
13 |
+
def ocr():
|
14 |
+
img = request.files['image']
|
15 |
+
img.save('temp.jpg')
|
16 |
+
text = pytesseract.image_to_string(Image.open('temp.jpg'))
|
17 |
+
return jsonify({'text': text})
|
18 |
+
|
19 |
+
@app.route('/plantuml', methods=['POST'])
|
20 |
+
def plantuml_diagram():
|
21 |
+
code = request.form['code']
|
22 |
+
diagram = plantuml.get_svg_string(code)
|
23 |
+
return jsonify({'diagram': diagram})
|
24 |
|
25 |
if __name__ == '__main__':
|
|
|
26 |
app.run(debug=True)
|
controllers/ai/app/admin.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from django.contrib import admin
|
2 |
+
|
3 |
+
admin.site.site_header = 'OCR App Admin'
|
controllers/ai/app/apps.py
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.apps import AppConfig
|
2 |
+
|
3 |
+
class AppConfig(AppConfig):
|
4 |
+
name = 'app'
|
5 |
+
verbose_name = 'OCR App'
|
controllers/ai/app/controllers/google_ocr.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from google.oauth2 import service_account
|
3 |
+
from googleapiclient.discovery import build
|
4 |
+
from googleapiclient.errors import HttpError
|
5 |
+
|
6 |
+
def google_ocr(image_path):
|
7 |
+
"""
|
8 |
+
Use Google Apps Script to extract text from an image using OCR
|
9 |
+
"""
|
10 |
+
SCOPES = ['https://www.googleapis.com/auth/script.external_request']
|
11 |
+
SERVICE_ACCOUNT_FILE = 'path/to/service_account_key.json'
|
12 |
+
|
13 |
+
credentials = service_account.Credentials.from_service_account_file(
|
14 |
+
SERVICE_ACCOUNT_FILE, SCOPES)
|
15 |
+
service = build('script', 'v1', credentials=credentials)
|
16 |
+
|
17 |
+
with open(image_path, 'rb') as f:
|
18 |
+
image_data = f.read()
|
19 |
+
|
20 |
+
request_body = {
|
21 |
+
'requests': [
|
22 |
+
{
|
23 |
+
'image': {
|
24 |
+
'content': image_data
|
25 |
+
},
|
26 |
+
'features': [
|
27 |
+
{
|
28 |
+
'type': 'TEXT_DETECTION'
|
29 |
+
}
|
30 |
+
]
|
31 |
+
}
|
32 |
+
]
|
33 |
+
}
|
34 |
+
|
35 |
+
try:
|
36 |
+
response = service.scripts().run(body=request_body).execute()
|
37 |
+
text = response['responses'][0]['textAnnotations'][0]['description']
|
38 |
+
return text
|
39 |
+
except HttpError as e:
|
40 |
+
print(f'Error: {e}')
|
41 |
+
return None
|
controllers/ai/app/controllers/logger.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import logging
|
2 |
+
|
3 |
+
class Logger:
|
4 |
+
def __init__(self):
|
5 |
+
self.logger = logging.getLogger('ocr_logger')
|
6 |
+
self.logger.setLevel(logging.INFO)
|
7 |
+
|
8 |
+
def loggers(self, message):
|
9 |
+
self.logger.info(message)
|
controllers/ai/app/controllers/ocr.py
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pytesseract
|
2 |
+
from PIL import Image
|
3 |
+
import os
|
4 |
+
|
5 |
+
def ocr_image(image_path):
|
6 |
+
"""
|
7 |
+
Extract text from an image using OCR
|
8 |
+
"""
|
9 |
+
img = Image.open(image_path)
|
10 |
+
text = pytesseract.image_to_string(img)
|
11 |
+
return text
|
controllers/ai/app/forms.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django import forms
|
2 |
+
from .models import WebSite
|
3 |
+
|
4 |
+
class WebSiteForm(forms.ModelForm):
|
5 |
+
class Meta:
|
6 |
+
model = WebSite
|
7 |
+
fields = ('name', 'url')
|
controllers/ai/app/models.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.db import models
|
2 |
+
|
3 |
+
class WebSite(models.Model):
|
4 |
+
name = models.CharField(max_length=255)
|
5 |
+
url = models.URLField(max_length=255)
|
6 |
+
|
7 |
+
def __str__(self):
|
8 |
+
return self.name
|
controllers/ai/app/templates/base.html
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<title>Web Scraping App</title>
|
5 |
+
</head>
|
6 |
+
<body>
|
7 |
+
<h1>Web Scraping App</h1>
|
8 |
+
<div id="content">
|
9 |
+
{% block content %}{% endblock %}
|
10 |
+
</div>
|
11 |
+
</body>
|
12 |
+
</html>
|
controllers/ai/app/templates/create_website.html
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{% extends 'base.html' %}
|
2 |
+
|
3 |
+
{% block content %}
|
4 |
+
<h1>Create Website</h1>
|
5 |
+
<form method="post">
|
6 |
+
{% csrf_token %}
|
7 |
+
{{ form.as_p }}
|
8 |
+
<button type="submit">Create</button>
|
9 |
+
</form>
|
10 |
+
{% endblock %}
|
controllers/ai/app/templates/index.html
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{% extends 'base.html' %}
|
2 |
+
|
3 |
+
{% block content %}
|
4 |
+
<h2>Websites</h2>
|
5 |
+
<ul>
|
6 |
+
{% for website in websites %}
|
7 |
+
<li>{{ website.name }} ({{ website.url }})</li>
|
8 |
+
{% empty %}
|
9 |
+
<li>No websites available.</li>
|
10 |
+
{% endfor %}
|
11 |
+
</ul>
|
12 |
+
{% endblock %}
|
controllers/ai/app/templates/scrape_result.html
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{% extends 'base.html' %}
|
2 |
+
|
3 |
+
{% block content %}
|
4 |
+
<h1>Scrape Result</h1>
|
5 |
+
<ul>
|
6 |
+
{% for product in products %}
|
7 |
+
<li>{{ product.name }} ({{ product.price }})</li>
|
8 |
+
{% endfor %}
|
9 |
+
</ul>
|
10 |
+
{% endblock %}
|
controllers/ai/app/urls.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.urls import path
|
2 |
+
from . import views
|
3 |
+
|
4 |
+
urlpatterns = [
|
5 |
+
path('', views.index, name='index'),
|
6 |
+
]
|
controllers/ai/app/views.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.shortcuts import render
|
2 |
+
from .models import WebSite
|
3 |
+
|
4 |
+
def index(request):
|
5 |
+
websites = WebSite.objects.all()
|
6 |
+
return render(request, 'index.html', {'websites': websites})
|
controllers/ai/appscript.gs
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
function onEdit(e) {
|
2 |
+
var sheet = e.source.getActiveSheet();
|
3 |
+
var range = e.range;
|
4 |
+
|
5 |
+
// Call Python script to process OCR result
|
6 |
+
var pythonScript = "python manage.py ocr_view";
|
7 |
+
var ocrResult = UrlFetchApp.fetch(pythonScript);
|
8 |
+
|
9 |
+
// Insert OCR result into Google Chat
|
10 |
+
var chatService = getService();
|
11 |
+
var spaceName = 'spaces/AAAA';
|
12 |
+
var message = {'text': ocrResult.getContentText()};
|
13 |
+
chatService.spaces.messages.create({
|
14 |
+
'parent': spaceName,
|
15 |
+
'resource': message
|
16 |
+
});
|
17 |
+
}
|
18 |
+
|
19 |
+
function getService() {
|
20 |
+
var service = OAuth2.createService('chat')
|
21 |
+
.setAuthorizationBaseUrl('https://accounts.google.com')
|
22 |
+
.setTokenUrl('https://accounts.google.com/o/oauth2/token')
|
23 |
+
.setClientId('your_client_id')
|
24 |
+
.setClientSecret('your_client_secret')
|
25 |
+
.setCallbackFunction('authCallback')
|
26 |
+
.setPropertyStore(PropertiesService.getUserProperties());
|
27 |
+
return service;
|
28 |
+
}
|
29 |
+
|
30 |
+
function authCallback(request) {
|
31 |
+
var service = getService();
|
32 |
+
var authorized = service.handleCallback(request);
|
33 |
+
if (authorized) {
|
34 |
+
return HtmlService.createHtmlOutput('Authorized');
|
35 |
+
} else {
|
36 |
+
return HtmlService.createHtmlOutput('Not authorized');
|
37 |
+
}
|
38 |
+
}
|
controllers/ai/command
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
python manage.py runserver
|
controllers/ai/commands
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
python manage.py makemigrations
|
2 |
+
python manage.py migrate
|
3 |
+
python manage.py runserver
|
controllers/ai/gradio_app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from app import app
|
3 |
+
|
4 |
+
with gr.Blocks() as demo:
|
5 |
+
img = gr.Image(type="pil")
|
6 |
+
btn = gr.Button("Run OCR")
|
7 |
+
txt = gr.Textbox(label="Extracted Text")
|
8 |
+
plantuml_code = gr.Textbox(label="PlantUML Code")
|
9 |
+
plantuml_diagram = gr.Image(type="pil")
|
10 |
+
|
11 |
+
def ocr(img):
|
12 |
+
response = app.post('/ocr', files={'image': img})
|
13 |
+
return response.json()['text']
|
14 |
+
|
15 |
+
def plantuml_diagram(code):
|
16 |
+
response = app.post('/plantuml', data={'code': code})
|
17 |
+
return response.json()['diagram']
|
18 |
+
|
19 |
+
btn.click(ocr, inputs=img, outputs=txt)
|
20 |
+
btn.click(plantuml_diagram, inputs=plantuml_code, outputs=plantuml_diagram)
|
21 |
+
|
22 |
+
demo.launch()
|
controllers/ai/manage.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
import os
|
3 |
+
import sys
|
4 |
+
|
5 |
+
if __name__ == "__main__":
|
6 |
+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
|
7 |
+
try:
|
8 |
+
from django.core.management import execute_from_command_line
|
9 |
+
except ImportError as exc:
|
10 |
+
raise ImportError(
|
11 |
+
"Couldn't import Django. Are you sure it's installed and "
|
12 |
+
"available on your PYTHONPATH environment variable? Did you "
|
13 |
+
"forget to activate a virtual environment?"
|
14 |
+
) from exc
|
15 |
+
execute_from_command_line(sys.argv)
|
controllers/ai/mysite/asgi.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from django.core.asgi import get_asgi_application
|
3 |
+
|
4 |
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
|
5 |
+
|
6 |
+
application = get_asgi_application()
|
controllers/ai/mysite/settings.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
INSTALLED_APPS = [
|
2 |
+
# ...
|
3 |
+
'polls.apps.PollsConfig',
|
4 |
+
# ...
|
5 |
+
]
|
6 |
+
|
7 |
+
MEDIA_ROOT = 'media/'
|
8 |
+
MEDIA_URL = '/media/'
|
controllers/ai/mysite/urls.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.contrib import admin
|
2 |
+
from django.urls import include, path
|
3 |
+
|
4 |
+
urlpatterns = [
|
5 |
+
path('polls/', include('polls.urls')),
|
6 |
+
path('admin/', admin.site.urls),
|
7 |
+
]
|
controllers/ai/polls/models.py
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.db import models
|
2 |
+
|
3 |
+
class ImageModel(models.Model):
|
4 |
+
image = models.ImageField(upload_to='images/')
|
5 |
+
ocr_text = models.TextField(blank=True)
|
controllers/ai/polls/ocr.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pytesseract
|
2 |
+
from PIL import Image
|
3 |
+
|
4 |
+
def ocr_extract_text(image_path):
|
5 |
+
image = Image.open(image_path)
|
6 |
+
text = pytesseract.image_to_string(image)
|
7 |
+
return text
|
controllers/ai/polls/templates/base.html
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<title>OCR App</title>
|
5 |
+
</head>
|
6 |
+
<body>
|
7 |
+
<h1>OCR App</h1>
|
8 |
+
<form method="post">
|
9 |
+
{% csrf_token %}
|
10 |
+
<input type="text" name="img_ocr" placeholder="Enter OCR result">
|
11 |
+
<button type="submit">Save OCR result</button>
|
12 |
+
</form>
|
13 |
+
<hr>
|
14 |
+
<a href="{% url 'plantuml_view' %}">View PlantUML diagram</a>
|
15 |
+
</body>
|
16 |
+
</html>
|
controllers/ai/polls/templates/polls/index.html
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<title>OCR App</title>
|
5 |
+
</head>
|
6 |
+
<body>
|
7 |
+
<h1>OCR App</h1>
|
8 |
+
<form method="post" enctype="multipart/form-data">
|
9 |
+
{% csrf_token %}
|
10 |
+
<input type="file" name="image">
|
11 |
+
<button type="submit">Upload Image</button>
|
12 |
+
</form>
|
13 |
+
{% if ocr_text %}
|
14 |
+
<p>Extracted Text: {{ ocr_text }}</p>
|
15 |
+
{% endif %}
|
16 |
+
</body>
|
17 |
+
</html>
|
controllers/ai/polls/urls.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.urls import path
|
2 |
+
from . import views
|
3 |
+
|
4 |
+
urlpatterns = [
|
5 |
+
path('', views.index, name='index'),
|
6 |
+
]
|
controllers/ai/polls/views.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.shortcuts import render
|
2 |
+
from .models import ImageModel
|
3 |
+
from .ocr import ocr_extract_text
|
4 |
+
from googleapiclient.discovery import build
|
5 |
+
from google.oauth2 import service_account
|
6 |
+
|
7 |
+
def index(request):
|
8 |
+
if request.method == 'POST':
|
9 |
+
image = request.FILES['image']
|
10 |
+
img_obj = ImageModel(image=image)
|
11 |
+
img_obj.save()
|
12 |
+
ocr_text = ocr_extract_text(img_obj.image.path)
|
13 |
+
img_obj.ocr_text = ocr_text
|
14 |
+
img_obj.save()
|
15 |
+
return render(request, 'polls/index.html', {'ocr_text': ocr_text})
|
16 |
+
return render(request, 'polls/index.html')
|
17 |
+
|
18 |
+
def google_chat_insert(text):
|
19 |
+
SCOPES = ['https://www.googleapis.com/auth/chat.service']
|
20 |
+
SERVICE_ACCOUNT_FILE = 'path/to/service_account_key.json'
|
21 |
+
credentials = service_account.Credentials.from_service_account_file(
|
22 |
+
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
|
23 |
+
chat_service = build('chat', 'v1', credentials=credentials)
|
24 |
+
request_body = {'text': text}
|
25 |
+
response = chat_service.spaces().messages().create(
|
26 |
+
parent='spaces/AAAA', body=request_body).execute()
|
27 |
+
print(response)
|
controllers/ai/project/settings.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from decouple import config
|
3 |
+
|
4 |
+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
5 |
+
|
6 |
+
SECRET_KEY = config('SECRET_KEY')
|
7 |
+
|
8 |
+
DEBUG = True
|
9 |
+
|
10 |
+
ALLOWED_HOSTS = []
|
11 |
+
|
12 |
+
INSTALLED_APPS = [
|
13 |
+
'django.contrib.admin',
|
14 |
+
'django.contrib.auth',
|
15 |
+
'django.contrib.contenttypes',
|
16 |
+
'django.contrib.sessions',
|
17 |
+
'django.contrib.messages',
|
18 |
+
'django.contrib.staticfiles',
|
19 |
+
'app',
|
20 |
+
]
|
21 |
+
|
22 |
+
MIDDLEWARE = [
|
23 |
+
'django.middleware.security.SecurityMiddleware',
|
24 |
+
'django.contrib.sessions.middleware.SessionMiddleware',
|
25 |
+
'django.middleware.common.CommonMiddleware',
|
26 |
+
'django.middleware.csrf.CsrfViewMiddleware',
|
27 |
+
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
28 |
+
'django.contrib.messages.middleware.MessageMiddleware',
|
29 |
+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
30 |
+
]
|
31 |
+
|
32 |
+
ROOT_URLCONF = 'project.urls'
|
33 |
+
|
34 |
+
TEMPLATES = [
|
35 |
+
{
|
36 |
+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
37 |
+
'DIRS': [os.path.join(BASE_DIR, 'templates')],
|
38 |
+
'APP_DIRS': True,
|
39 |
+
'OPTIONS': {
|
40 |
+
'context_processors': [
|
41 |
+
'django.template.context_processors.debug',
|
42 |
+
'django.template.context_processors.request',
|
43 |
+
'django.contrib.auth.context_processors.auth',
|
44 |
+
'django.contrib.messages.context_processors.messages',
|
45 |
+
],
|
46 |
+
},
|
47 |
+
},
|
48 |
+
]
|
49 |
+
|
50 |
+
WSGI_APPLICATION = 'project.wsgi.application'
|
51 |
+
|
52 |
+
DATABASES = {
|
53 |
+
'default': {
|
54 |
+
'ENGINE': 'django.db.backends.sqlite3',
|
55 |
+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
56 |
+
}
|
57 |
+
}
|
58 |
+
|
59 |
+
LANGUAGE_CODE = 'en-us'
|
60 |
+
|
61 |
+
TIME_ZONE = 'UTC'
|
62 |
+
|
63 |
+
USE_I18N = True
|
64 |
+
|
65 |
+
USE_L10N = True
|
66 |
+
|
67 |
+
USE_TZ = True
|
68 |
+
|
69 |
+
STATIC_URL = '/static/'
|
controllers/ai/project/urls.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.contrib import admin
|
2 |
+
from django.urls import path, include
|
3 |
+
|
4 |
+
urlpatterns = [
|
5 |
+
path('admin/', admin.site.urls),
|
6 |
+
path('', include('app.urls')),
|
7 |
+
]
|
controllers/ai/project/wsgi.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
from django.core.wsgi import get_wsgi_application
|
4 |
+
|
5 |
+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
|
6 |
+
|
7 |
+
application = get_wsgi_application()
|
controllers/ai/prompt
CHANGED
@@ -16,4 +16,180 @@ HTMLのサンプルを作成してtesttestOCRがうごいていないなOCRが
|
|
16 |
LINEREQ.google_chat_insert('///////⭐️⭐️⭐️⭐️個人情報の確認' + imgOcr);
|
17 |
//return;
|
18 |
}
|
19 |
-
//ocrデーhttps://script.google.com/home/projects/1VP-YBob1FwAb3W5iBOb07gYUGRAUCz3fE4EnXrLO-lSnCRoPpkRQulfD/edit?pli=1https://script.google.com/home/projects/1VP-YBob1FwAb3W5iBOb07gYUGRAUCz3fE4EnXrLO-lSnCRoPpkRQulfD/edit?pli=1gradio で plantumlを表示したいgradio で plantumlを表示したい
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
LINEREQ.google_chat_insert('///////⭐️⭐️⭐️⭐️個人情報の確認' + imgOcr);
|
17 |
//return;
|
18 |
}
|
19 |
+
//ocrデーhttps://script.google.com/home/projects/1VP-YBob1FwAb3W5iBOb07gYUGRAUCz3fE4EnXrLO-lSnCRoPpkRQulfD/edit?pli=1https://script.google.com/home/projects/1VP-YBob1FwAb3W5iBOb07gYUGRAUCz3fE4EnXrLO-lSnCRoPpkRQulfD/edit?pli=1gradio で plantumlを表示したいgradio で plantumlを表示したいpython manage.py startapp pollsspython manage.py startapp pollssdjango sample アプリケーションdjango sample アプリケーションdjangoのサンプルアプリケーションの作成djangoのサンプルアプリケーションの作成do itdo itこれをテスト /home/user/app/controllers/仕入れ先問屋さんの各ウェブサイト/run.shこれをテスト /home/user/app/controllers/仕入れ先問屋さんの各ウェブサイト/run.sh仕事の詳細
|
20 |
+
|
21 |
+
御覧いただきありがとうございます。
|
22 |
+
弊社はAMAZONや楽天等、ネット通販を主とした会社となります。
|
23 |
+
|
24 |
+
今回は、仕入れ先問屋さんの各ウェブサイトの
|
25 |
+
スクレイピング作業ならびに
|
26 |
+
仕様書作成やサーバー設置・運用等もしていただける方を募集いたします。
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
■業務内容---------------------------------------------------
|
31 |
+
|
32 |
+
|
33 |
+
①スクレイピング作業
|
34 |
+
仕様書を元に、指定問屋のWebサイトから全商品データ(約3,000件~50,000件以上)を収集して
|
35 |
+
xlsx形式で出力するpythonプログラムを作成し、動作確認及び取得データを提出する。
|
36 |
+
(すでに複数メンバーで対応中です。)
|
37 |
+
|
38 |
+
|
39 |
+
②サーバー設置、運用
|
40 |
+
スクレイピングのプログラムをX-ServerやVPS等に設置して毎日定期実行する。
|
41 |
+
※全商品データを毎日取得しDropboxへアップロードする必要があります。
|
42 |
+
不具合が発生した際は修正や再開等の対応を行い、毎日安定して取得できるようにする。
|
43 |
+
(すでに稼働中のスクレイピングも多数あり、他の方が作成したプログラムの設置や
|
44 |
+
不具合対応も必要になります。)
|
45 |
+
★Linuxの知識やpython定期実行の経験がある方が望ましいです。
|
46 |
+
|
47 |
+
|
48 |
+
③仕様書作成
|
49 |
+
他の作業者にスクレイピング作業を依頼するため、仕入れ先候補となるウェブサイトを確認し
|
50 |
+
効率的かつ安定してスクレイピングできる処理手順や各データの取得仕様を考えて仕様書を作成する。
|
51 |
+
(サーバー設置後の運用も考慮する。)
|
52 |
+
★小売業や問屋に関わる基本知識のある方が望ましいです。
|
53 |
+
|
54 |
+
|
55 |
+
現在の問屋数は約40社となり週4~5件ペースで追加を目標にしております。
|
56 |
+
|
57 |
+
サイトにもよりますが2日でプログラム作成、
|
58 |
+
1日で修正、完了を目安目標に作業していただいております。
|
59 |
+
|
60 |
+
|
61 |
+
また、PhantomJSでの動作やwindowsでの定期実行、
|
62 |
+
その他様々な工夫が必要な場合があるため、 経験ないことでも調べて対応頂ける方が望ましいです。
|
63 |
+
仕事の詳細
|
64 |
+
|
65 |
+
御覧いただきありがとうございます。
|
66 |
+
弊社はAMAZONや楽天等、ネット通販を主とした会社となります。
|
67 |
+
|
68 |
+
今回は、仕入れ先問屋さんの各ウェブサイトの
|
69 |
+
スクレイピング作業ならびに
|
70 |
+
仕様書作成やサーバー設置・運用等もしていただける方を募集いたします。
|
71 |
+
|
72 |
+
|
73 |
+
|
74 |
+
■業務内容---------------------------------------------------
|
75 |
+
|
76 |
+
|
77 |
+
①スクレイピング作業
|
78 |
+
仕様書を元に、指定問屋のWebサイトから全商品データ(約3,000件~50,000件以上)を収集して
|
79 |
+
xlsx形式で出力するpythonプログラムを作成し、動作確認及び取得データを提出する。
|
80 |
+
(すでに複数メンバーで対応中です。)
|
81 |
+
|
82 |
+
|
83 |
+
②サーバー設置、運用
|
84 |
+
スクレイピングのプログラムをX-ServerやVPS等に設置して毎日定期実行する。
|
85 |
+
※全商品データを毎日取得しDropboxへアップロードする必要があります。
|
86 |
+
不具合が発生した際は修正や再開等の対応を行い、毎日安定して取得できるようにする。
|
87 |
+
(すでに稼働中のスクレイピングも多数あり、他の方が作成したプログラムの設置や
|
88 |
+
不具合対応も必要になります。)
|
89 |
+
★Linuxの知識やpython定期実行の経験がある方が望ましいです。
|
90 |
+
|
91 |
+
|
92 |
+
③仕様書作成
|
93 |
+
他の作業者にスクレイピング作業を依頼するため、仕入れ先候補��なるウェブサイトを確認し
|
94 |
+
効率的かつ安定してスクレイピングできる処理手順や各データの取得仕様を考えて仕様書を作成する。
|
95 |
+
(サーバー設置後の運用も考慮する。)
|
96 |
+
★小売業や問屋に関わる基本知識のある方が望ましいです。
|
97 |
+
|
98 |
+
|
99 |
+
現在の問屋数は約40社となり週4~5件ペースで追加を目標にしております。
|
100 |
+
|
101 |
+
サイトにもよりますが2日でプログラム作成、
|
102 |
+
1日で修正、完了を目安目標に作業していただいております。
|
103 |
+
|
104 |
+
|
105 |
+
また、PhantomJSでの動作やwindowsでの定期実行、
|
106 |
+
その他様々な工夫が必要な場合があるため、 経験ないことでも調べて対応頂ける方が望ましいです。
|
107 |
+
仕事の詳細
|
108 |
+
|
109 |
+
御覧いただきありがとうございます。
|
110 |
+
弊社はAMAZONや楽天等、ネット通販を主とした会社となります。
|
111 |
+
|
112 |
+
今回は、仕入れ先問屋さんの各ウェブサイトの
|
113 |
+
スクレイピング作業ならびに
|
114 |
+
仕様書作成やサーバー設置・運用等もしていただける方を募集いたします。
|
115 |
+
|
116 |
+
|
117 |
+
|
118 |
+
■業務内容---------------------------------------------------
|
119 |
+
|
120 |
+
|
121 |
+
①スクレイピング作業
|
122 |
+
仕様書を元に、指定問屋のWebサイトから全商品データ(約3,000件~50,000件以上)を収集して
|
123 |
+
xlsx形式で出力するpythonプログラムを作成し、動作確認及び取得データを提出する。
|
124 |
+
(すでに複数メンバーで対応中です。)
|
125 |
+
|
126 |
+
|
127 |
+
②サーバー設置、運用
|
128 |
+
スクレイピングのプログラムをX-ServerやVPS等に設置して毎日定期実行する。
|
129 |
+
※全商品データを毎日取得しDropboxへアップロードする必要があります。
|
130 |
+
不具合が発生した際は修正や再開等の対応を行い、毎日安定して取得できるようにする。
|
131 |
+
(すでに稼働中のスクレイピングも多数あり、他の方が作成したプログラムの設置や
|
132 |
+
不具合対応も必要になります。)
|
133 |
+
★Linuxの知識やpython定期実行の経験がある方が望ましいです。
|
134 |
+
|
135 |
+
|
136 |
+
③仕様書作成
|
137 |
+
他の作業者にスクレイピング作業を依頼するため、仕入れ先候補となるウェブサイトを確認し
|
138 |
+
効率的かつ安定してスクレイピングできる処理手順や各データの取得仕様を考えて仕様書を作成する。
|
139 |
+
(サーバー設置後の運用も考慮する。)
|
140 |
+
★小売業や問屋に関わる基本知識のある方が望ましいです。
|
141 |
+
|
142 |
+
|
143 |
+
現在の問屋数は約40社となり週4~5件ペースで追加を目標にしております。
|
144 |
+
|
145 |
+
サイトにもよりますが2日でプログラム作成、
|
146 |
+
1日で修正、完了を目安目標に作業していただいております。
|
147 |
+
|
148 |
+
|
149 |
+
また、PhantomJSでの動作やwindowsでの定期実行、
|
150 |
+
その他様々な工夫が必要な場合があるため、 経験ないことでも調べて対応頂ける方が望ましいです。
|
151 |
+
仕事の詳細
|
152 |
+
|
153 |
+
御覧いただきありがとうございます。
|
154 |
+
弊社はAMAZONや楽天等、ネット通販を主とした会社となります。
|
155 |
+
|
156 |
+
今回は、仕入れ先問屋さんの各ウェブサイトの
|
157 |
+
スクレイピング作業ならびに
|
158 |
+
仕様書作成やサーバー設置・運用等もしていただける方を募集いたします。
|
159 |
+
|
160 |
+
|
161 |
+
|
162 |
+
■業務内容---------------------------------------------------
|
163 |
+
|
164 |
+
|
165 |
+
①スクレイピング作業
|
166 |
+
仕様書を元に、指定問屋のWebサイトから全商品データ(約3,000件~50,000件以上)を収集して
|
167 |
+
xlsx形式で出力するpythonプログラムを作成し、動作確認及び取得データを提出する。
|
168 |
+
(すでに複数メンバーで対応中です。)
|
169 |
+
|
170 |
+
|
171 |
+
②サーバー設置、運用
|
172 |
+
スクレイピングのプログラムをX-ServerやVPS等に設置して毎日定期実行する。
|
173 |
+
※全商品データを毎日取得しDropboxへアップロードする必要があります。
|
174 |
+
不具合が発生した際は修正や再開等の対応を行い、毎日安定して取得できるようにする。
|
175 |
+
(すでに稼働中のスクレイピングも多数あり、他の方が作成したプログラムの設置や
|
176 |
+
不具合対応も必要になります。)
|
177 |
+
★Linuxの知識やpython定期実行の経験がある方が望ましいです。
|
178 |
+
|
179 |
+
|
180 |
+
③仕様書作成
|
181 |
+
他の作業者にスクレイピング作業を依頼するため、仕入れ先候補となるウェブサイトを確認し
|
182 |
+
効率的かつ安定してスクレイピングできる処理手順や各データの取得仕様を考えて仕様書を作成する。
|
183 |
+
(サーバー設置後の運用も考慮する。)
|
184 |
+
★小売業や問屋に関わる基本知識のある方が望ましいです。
|
185 |
+
|
186 |
+
|
187 |
+
現在の問屋数は約40社となり週4~5件ペースで追加を目標にしております。
|
188 |
+
|
189 |
+
サイトにもよりますが2日でプログラム作成、
|
190 |
+
1日で修正、完了を目安目標に作業していただいております。
|
191 |
+
|
192 |
+
|
193 |
+
また、PhantomJSでの動作やwindowsでの定期実行、
|
194 |
+
その他様々な工夫が必要な場合があるため、 経験ないことでも調べて対応頂ける方が望ましいです。
|
195 |
+
ls -alls -alpwdpwdls -alls -al
|
controllers/ai/requirements.txt
CHANGED
@@ -1,5 +1,2 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
pytesseract
|
4 |
-
google-api-python-client
|
5 |
-
google-auth
|
|
|
1 |
+
Django==3.2.5
|
2 |
+
python-decouple==3.4
|
|
|
|
|
|
controllers/ai/run.sh
CHANGED
@@ -3,6 +3,5 @@
|
|
3 |
# Install dependencies
|
4 |
pip install -r requirements.txt
|
5 |
|
6 |
-
# Run the
|
7 |
-
python
|
8 |
-
gradio app.py &
|
|
|
3 |
# Install dependencies
|
4 |
pip install -r requirements.txt
|
5 |
|
6 |
+
# Run the Django development server
|
7 |
+
python manage.py runserver
|
|
controllers/ai/static/css/style.css
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
body {
|
2 |
+
font-family: Arial, sans-serif;
|
3 |
+
}
|
4 |
+
|
5 |
+
header {
|
6 |
+
background-color: #f0f0f0;
|
7 |
+
padding: 20px;
|
8 |
+
text-align: center;
|
9 |
+
}
|
10 |
+
|
11 |
+
nav ul {
|
12 |
+
list-style: none;
|
13 |
+
margin: 0;
|
14 |
+
padding: 0;
|
15 |
+
}
|
16 |
+
|
17 |
+
nav li {
|
18 |
+
display: inline-block;
|
19 |
+
margin-right: 20px;
|
20 |
+
}
|
21 |
+
|
22 |
+
nav a {
|
23 |
+
color: #337ab7;
|
24 |
+
text-decoration: none;
|
25 |
+
}
|
26 |
+
|
27 |
+
nav a:hover {
|
28 |
+
color: #23527c;
|
29 |
+
}
|
30 |
+
|
31 |
+
main {
|
32 |
+
display: flex;
|
33 |
+
flex-direction: column;
|
34 |
+
align-items: center;
|
35 |
+
padding: 20px;
|
36 |
+
}
|
37 |
+
|
38 |
+
table {
|
39 |
+
border-collapse: collapse;
|
40 |
+
width: 100%;
|
41 |
+
}
|
42 |
+
|
43 |
+
th, td {
|
44 |
+
border: 1px solid #ddd;
|
45 |
+
padding: 10px;
|
46 |
+
text-align: left;
|
47 |
+
}
|
48 |
+
|
49 |
+
th {
|
50 |
+
background-color: #f0f0f0;
|
51 |
+
}
|
controllers/ai/templates/base.html
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<title>Web Scraping</title>
|
5 |
+
<link rel="stylesheet" href="{% static 'css/style.css' %}">
|
6 |
+
</head>
|
7 |
+
<body>
|
8 |
+
<header>
|
9 |
+
<nav>
|
10 |
+
<ul>
|
11 |
+
{% for website in websites %}
|
12 |
+
<li><a href="{% url 'scrape_website' website.pk %}">{{ website.name }}</a></li>
|
13 |
+
{% endfor %}
|
14 |
+
</ul>
|
15 |
+
</nav>
|
16 |
+
</header>
|
17 |
+
<main>
|
18 |
+
{% block content %}{% endblock %}
|
19 |
+
</main>
|
20 |
+
</body>
|
21 |
+
</html>
|
controllers/ai/templates/index.html
CHANGED
@@ -1,32 +1,10 @@
|
|
1 |
-
|
2 |
-
<html>
|
3 |
-
<head>
|
4 |
-
<title>OCR App</title>
|
5 |
-
</head>
|
6 |
-
<body>
|
7 |
-
<h1>OCR App</h1>
|
8 |
-
<form id="ocr-form">
|
9 |
-
<input type="file" id="image" name="image">
|
10 |
-
<button type="submit">Submit</button>
|
11 |
-
</form>
|
12 |
-
<div id="result"></div>
|
13 |
|
14 |
-
|
15 |
-
<
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
axios.post('/ocr', formData)
|
23 |
-
.then(response => {
|
24 |
-
document.getElementById('result').innerHTML = `OCR result: ${response.data.message}`;
|
25 |
-
})
|
26 |
-
.catch(error => {
|
27 |
-
console.error(error);
|
28 |
-
});
|
29 |
-
});
|
30 |
-
</script>
|
31 |
-
</body>
|
32 |
-
</html>
|
|
|
1 |
+
{% extends 'base.html' %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
{% block content %}
|
4 |
+
<h1>Websites</h1>
|
5 |
+
<ul>
|
6 |
+
{% for website in websites %}
|
7 |
+
<li>{{ website.name }} ({{ website.url }})</li>
|
8 |
+
{% endfor %}
|
9 |
+
</ul>
|
10 |
+
{% endblock %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
controllers/ai/templates/specification.html
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{% extends 'base.html' %}
|
2 |
+
|
3 |
+
{% block content %}
|
4 |
+
<h1>Specification</h1>
|
5 |
+
<table>
|
6 |
+
<tr>
|
7 |
+
<th>Key</th>
|
8 |
+
<th>Value</th>
|
9 |
+
</tr>
|
10 |
+
{% for spec in specification %}
|
11 |
+
<tr>
|
12 |
+
<td>{{ spec.key }}</td>
|
13 |
+
<td>{{ spec.value }}</td>
|
14 |
+
</tr>
|
15 |
+
{% endfor %}
|
16 |
+
</table>
|
17 |
+
{% endblock %}
|
controllers/gra_02_openInterpreter/OpenInterpreter.py
CHANGED
@@ -60,36 +60,80 @@ def format_response(chunk, full_response):
|
|
60 |
|
61 |
return full_response
|
62 |
|
|
|
|
|
63 |
|
64 |
-
#
|
65 |
-
|
66 |
-
message, history, a=None, b=None, c=None, d=None
|
67 |
-
): # , openai_api_key):
|
68 |
-
# Set the API key for the interpreter
|
69 |
-
# interpreter.llm.api_key = openai_api_key
|
70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
if message == "reset":
|
72 |
-
interpreter.messages = []
|
73 |
interpreter.reset()
|
74 |
return "Interpreter reset", history
|
|
|
75 |
full_response = ""
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
77 |
user_entry = {"role": "user", "type": "message", "content": message}
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
# result = interpreter.chat(message)
|
82 |
for chunk in interpreter.chat(message, display=False, stream=True):
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
89 |
|
90 |
yield full_response
|
91 |
return full_response, history
|
92 |
|
|
|
|
|
|
|
|
|
93 |
PLACEHOLDER = """
|
94 |
<div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
|
95 |
<img src="https://ysharma-dummy-chat-app.hf.space/file=/tmp/gradio/8e75e61cc9bab22b7ce3dec85ab0e6db1da5d107/Meta_lockup_positive%20primary_RGB.jpg" style="width: 80%; max-width: 550px; height: auto; opacity: 0.55; ">
|
|
|
60 |
|
61 |
return full_response
|
62 |
|
63 |
+
import sqlite3
|
64 |
+
from datetime import datetime
|
65 |
|
66 |
+
# SQLiteの設定
|
67 |
+
db_name = "chat_history.db"
|
|
|
|
|
|
|
|
|
68 |
|
69 |
+
def initialize_db():
|
70 |
+
conn = sqlite3.connect(db_name)
|
71 |
+
cursor = conn.cursor()
|
72 |
+
cursor.execute("""
|
73 |
+
CREATE TABLE IF NOT EXISTS history (
|
74 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
75 |
+
role TEXT,
|
76 |
+
type TEXT,
|
77 |
+
content TEXT,
|
78 |
+
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
|
79 |
+
)
|
80 |
+
""")
|
81 |
+
conn.commit()
|
82 |
+
conn.close()
|
83 |
+
|
84 |
+
def add_message_to_db(role, message_type, content):
|
85 |
+
conn = sqlite3.connect(db_name)
|
86 |
+
cursor = conn.cursor()
|
87 |
+
cursor.execute("INSERT INTO history (role, type, content) VALUES (?, ?, ?)", (role, message_type, content))
|
88 |
+
conn.commit()
|
89 |
+
conn.close()
|
90 |
+
|
91 |
+
def get_recent_messages(limit=20):
|
92 |
+
conn = sqlite3.connect(db_name)
|
93 |
+
cursor = conn.cursor()
|
94 |
+
cursor.execute("SELECT role, type, content FROM history ORDER BY timestamp DESC LIMIT ?", (limit,))
|
95 |
+
messages = cursor.fetchall()
|
96 |
+
conn.close()
|
97 |
+
return messages[::-1] # 最新の20件を取得して逆順にする
|
98 |
+
|
99 |
+
def format_responses(chunk, full_response):
|
100 |
+
# This function will format the response from the interpreter
|
101 |
+
return full_response + chunk.get("content", "")
|
102 |
+
|
103 |
+
def chat_with_interpreter(message, history, a=None, b=None, c=None, d=None):
|
104 |
if message == "reset":
|
|
|
105 |
interpreter.reset()
|
106 |
return "Interpreter reset", history
|
107 |
+
|
108 |
full_response = ""
|
109 |
+
recent_messages = get_recent_messages()
|
110 |
+
|
111 |
+
for role, message_type, content in recent_messages:
|
112 |
+
entry = {"role": role, "type": message_type, "content": content}
|
113 |
+
interpreter.messages.append(entry)
|
114 |
+
|
115 |
user_entry = {"role": "user", "type": "message", "content": message}
|
116 |
+
interpreter.messages.append(user_entry)
|
117 |
+
add_message_to_db("user", "message", message)
|
118 |
+
|
|
|
119 |
for chunk in interpreter.chat(message, display=False, stream=True):
|
120 |
+
if isinstance(chunk, dict):
|
121 |
+
full_response = format_response(chunk, full_response)
|
122 |
+
else:
|
123 |
+
raise TypeError("Expected chunk to be a dictionary")
|
124 |
+
yield full_response
|
125 |
+
|
126 |
+
assistant_entry = {"role": "assistant", "type": "message", "content": full_response}
|
127 |
+
interpreter.messages.append(assistant_entry)
|
128 |
+
add_message_to_db("assistant", "message", full_response)
|
129 |
|
130 |
yield full_response
|
131 |
return full_response, history
|
132 |
|
133 |
+
# 初期化
|
134 |
+
initialize_db()
|
135 |
+
|
136 |
+
|
137 |
PLACEHOLDER = """
|
138 |
<div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
|
139 |
<img src="https://ysharma-dummy-chat-app.hf.space/file=/tmp/gradio/8e75e61cc9bab22b7ce3dec85ab0e6db1da5d107/Meta_lockup_positive%20primary_RGB.jpg" style="width: 80%; max-width: 550px; height: auto; opacity: 0.55; ">
|
controllers/test_folders/prompt
DELETED
@@ -1,21 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
|
3 |
-
class GradioInterface:
|
4 |
-
ifrac:any
|
5 |
-
def __init__(self):
|
6 |
-
self iface = Interface(
|
7 |
-
fn=self.predict,
|
8 |
-
inputs="image",
|
9 |
-
outputs="text",
|
10 |
-
title="Image Search",
|
11 |
-
description="Search for images using Google Apps Script"
|
12 |
-
)
|
13 |
-
|
14 |
-
def predict(self, img):
|
15 |
-
# Implement image search logic using Google Apps Script
|
16 |
-
pass
|
17 |
-
|
18 |
-
def launch(self):
|
19 |
-
self.iface.launch()
|
20 |
-
|
21 |
-
gradio_intarface = GradioInterface().ifrac
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
controllers/test_folderszd/requirements.txt
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
gradio
|
|
|
|
projectname/manage.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
"""Django's command-line utility for administrative tasks."""
|
3 |
+
import os
|
4 |
+
import sys
|
5 |
+
|
6 |
+
|
7 |
+
def main():
|
8 |
+
"""Run administrative tasks."""
|
9 |
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'projectname.settings')
|
10 |
+
try:
|
11 |
+
from django.core.management import execute_from_command_line
|
12 |
+
except ImportError as exc:
|
13 |
+
raise ImportError(
|
14 |
+
"Couldn't import Django. Are you sure it's installed and "
|
15 |
+
"available on your PYTHONPATH environment variable? Did you "
|
16 |
+
"forget to activate a virtual environment?"
|
17 |
+
) from exc
|
18 |
+
execute_from_command_line(sys.argv)
|
19 |
+
|
20 |
+
|
21 |
+
if __name__ == '__main__':
|
22 |
+
main()
|
{controllers/test_folders → projectname/pollss}/__init__.py
RENAMED
File without changes
|
projectname/pollss/admin.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from django.contrib import admin
|
2 |
+
|
3 |
+
# Register your models here.
|
projectname/pollss/apps.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.apps import AppConfig
|
2 |
+
|
3 |
+
|
4 |
+
class PollssConfig(AppConfig):
|
5 |
+
default_auto_field = 'django.db.models.BigAutoField'
|
6 |
+
name = 'pollss'
|
{controllers/test_plantuml → projectname/pollss/migrations}/__init__.py
RENAMED
File without changes
|