simonlee-cb commited on
Commit
b675cf6
·
0 Parent(s):

initial commit

Browse files
Files changed (4) hide show
  1. .gitignore +192 -0
  2. app.py +61 -0
  3. poetry.lock +0 -0
  4. pyproject.toml +17 -0
.gitignore ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ *.egg-info/
24
+ .installed.cfg
25
+ *.egg
26
+ MANIFEST
27
+
28
+ # PyInstaller
29
+ # Usually these files are written by a python script from a template
30
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
31
+ *.manifest
32
+ *.spec
33
+
34
+ # Installer logs
35
+ pip-log.txt
36
+ pip-delete-this-directory.txt
37
+
38
+ # Unit test / coverage reports
39
+ htmlcov/
40
+ .tox/
41
+ .coverage
42
+ .coverage.*
43
+ .cache
44
+ nosetests.xml
45
+ coverage.xml
46
+ *.cover
47
+ .hypothesis/
48
+ .pytest_cache/
49
+
50
+ # Translations
51
+ *.mo
52
+ *.pot
53
+
54
+ # Django stuff:
55
+ *.log
56
+ local_settings.py
57
+ db.sqlite3
58
+
59
+ # Flask stuff:
60
+ instance/
61
+ .webassets-cache
62
+
63
+ # Scrapy stuff:
64
+ .scrapy
65
+
66
+ # Sphinx documentation
67
+ docs/_build/
68
+
69
+ # PyBuilder
70
+ target/
71
+
72
+ # Jupyter Notebook
73
+ .ipynb_checkpoints
74
+
75
+ # pyenv
76
+ .python-version
77
+
78
+ # celery beat schedule file
79
+ celerybeat-schedule
80
+
81
+ # SageMath parsed files
82
+ *.sage.py
83
+
84
+ # Environments
85
+ .env
86
+ .venv
87
+ env/
88
+ venv/
89
+ ENV/
90
+ env.bak/
91
+ venv.bak/
92
+
93
+ # Spyder project settings
94
+ .spyderproject
95
+ .spyproject
96
+
97
+ # Rope project settings
98
+ .ropeproject
99
+
100
+ # mkdocs documentation
101
+ /site
102
+
103
+ # mypy
104
+ .mypy_cache/
105
+
106
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
107
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
108
+
109
+ # User-specific stuff
110
+ .idea/**/workspace.xml
111
+ .idea/**/tasks.xml
112
+ .idea/**/usage.statistics.xml
113
+ .idea/**/dictionaries
114
+ .idea/**/shelf
115
+
116
+ # Generated files
117
+ .idea/**/contentModel.xml
118
+
119
+ # Sensitive or high-churn files
120
+ .idea/**/dataSources/
121
+ .idea/**/dataSources.ids
122
+ .idea/**/dataSources.local.xml
123
+ .idea/**/sqlDataSources.xml
124
+ .idea/**/dynamic.xml
125
+ .idea/**/uiDesigner.xml
126
+ .idea/**/dbnavigator.xml
127
+
128
+ # Gradle
129
+ .idea/**/gradle.xml
130
+ .idea/**/libraries
131
+
132
+ # Gradle and Maven with auto-import
133
+ # When using Gradle or Maven with auto-import, you should exclude module files,
134
+ # since they will be recreated, and may cause churn. Uncomment if using
135
+ # auto-import.
136
+ # .idea/modules.xml
137
+ # .idea/*.iml
138
+ # .idea/modules
139
+ # *.iml
140
+ # *.ipr
141
+
142
+ # CMake
143
+ cmake-build-*/
144
+
145
+ # Mongo Explorer plugin
146
+ .idea/**/mongoSettings.xml
147
+
148
+ # File-based project format
149
+ *.iws
150
+
151
+ # IntelliJ
152
+ out/
153
+
154
+ # mpeltonen/sbt-idea plugin
155
+ .idea_modules/
156
+
157
+ # JIRA plugin
158
+ atlassian-ide-plugin.xml
159
+
160
+ # Cursive Clojure plugin
161
+ .idea/replstate.xml
162
+
163
+ # Crashlytics plugin (for Android Studio and IntelliJ)
164
+ com_crashlytics_export_strings.xml
165
+ crashlytics.properties
166
+ crashlytics-build.properties
167
+ fabric.properties
168
+
169
+ # Editor-based Rest Client
170
+ .idea/httpRequests
171
+
172
+ # Android studio 3.1+ serialized cache file
173
+ .idea/caches/build_file_checksums.ser
174
+
175
+ # All .idea
176
+ .idea/
177
+
178
+ # vs code
179
+ .vscode/*
180
+ !.vscode/settings.json
181
+ !.vscode/tasks.json
182
+ !.vscode/launch.json
183
+ !.vscode/extensions.json
184
+ *.code-workspace
185
+ .vscode/
186
+
187
+ # Virtual Environment
188
+ venv
189
+ venv/
190
+
191
+ # Streamlit
192
+ .streamlit/
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from openai import OpenAI
2
+ import streamlit as st
3
+ import base64
4
+
5
+ st.title("ChatGPT-like clone")
6
+
7
+ def encode_image(uploaded_file):
8
+ # Read the file directly from the UploadedFile object
9
+ return base64.b64encode(uploaded_file.read()).decode("utf-8")
10
+
11
+ client = OpenAI(api_key=st.secrets["OPENAI_API_KEY"])
12
+ image = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
13
+
14
+ if image is not None:
15
+ st.session_state.image = image
16
+
17
+ if "openai_model" not in st.session_state:
18
+ st.session_state["openai_model"] = "gpt-4o"
19
+
20
+ if "messages" not in st.session_state:
21
+ st.session_state.messages = []
22
+
23
+ for message in st.session_state.messages:
24
+ with st.chat_message(message["role"]):
25
+ for content in message["content"]:
26
+ if content["type"] == "text":
27
+ st.markdown(content["text"])
28
+ elif content["type"] == "image_url":
29
+ st.image(content["image_url"]["url"])
30
+
31
+ if prompt := st.chat_input("What is up?"):
32
+ # Add image to the message if it exists
33
+ if st.session_state.image:
34
+ image_data = encode_image(st.session_state.image)
35
+ image_url = f"data:image/jpeg;base64,{image_data}"
36
+ st.session_state.messages.append({"role": "user", "content": [
37
+ {"type": "text", "text": prompt},
38
+ {"type": "image_url", "image_url": {"url": image_url}}
39
+ ]})
40
+ else:
41
+ st.session_state.messages.append({"role": "user", "content": [
42
+ {"type": "text", "text": prompt}
43
+ ]})
44
+
45
+ with st.chat_message("user"):
46
+ st.image(st.session_state.image)
47
+ st.markdown(prompt)
48
+
49
+ with st.chat_message("assistant"):
50
+ stream = client.chat.completions.create(
51
+ model=st.session_state["openai_model"],
52
+ messages=[
53
+ {"role": m["role"], "content": m["content"]}
54
+ for m in st.session_state.messages
55
+ ],
56
+ stream=True,
57
+ )
58
+ response = st.write_stream(stream)
59
+ st.session_state.messages.append({"role": "assistant", "content": [
60
+ {"type": "text", "text": response}
61
+ ]})
poetry.lock ADDED
The diff for this file is too large to render. See raw diff
 
pyproject.toml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [tool.poetry]
2
+ name = "conversational-image-editor"
3
+ version = "0.1.0"
4
+ description = ""
5
+ authors = ["Simon Lee <[email protected]>"]
6
+ readme = "README.md"
7
+
8
+ [tool.poetry.dependencies]
9
+ python = "3.10"
10
+ streamlit = "^1.42.0"
11
+ openai = "^1.63.0"
12
+ watchdog = "^6.0.0"
13
+
14
+
15
+ [build-system]
16
+ requires = ["poetry-core"]
17
+ build-backend = "poetry.core.masonry.api"