yvoievid commited on
Commit
67143f7
Β·
1 Parent(s): b429427

[refactoring] code cleanage

Browse files
Files changed (3) hide show
  1. .gitignore +163 -1
  2. app.py +14 -38
  3. model.py +24 -0
.gitignore CHANGED
@@ -1 +1,163 @@
1
- .streamlit/secrets.toml
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ .streamlit/
3
+ __pycache__/
4
+ *.py[cod]
5
+ *$py.class
6
+
7
+ # C extensions
8
+ *.so
9
+
10
+ # Distribution / packaging
11
+ .Python
12
+ build/
13
+ develop-eggs/
14
+ dist/
15
+ downloads/
16
+ eggs/
17
+ .eggs/
18
+ lib/
19
+ lib64/
20
+ parts/
21
+ sdist/
22
+ var/
23
+ wheels/
24
+ share/python-wheels/
25
+ *.egg-info/
26
+ .installed.cfg
27
+ *.egg
28
+ MANIFEST
29
+
30
+ # PyInstaller
31
+ # Usually these files are written by a python script from a template
32
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
33
+ *.manifest
34
+ *.spec
35
+
36
+ # Installer logs
37
+ pip-log.txt
38
+ pip-delete-this-directory.txt
39
+
40
+ # Unit test / coverage reports
41
+ htmlcov/
42
+ .tox/
43
+ .nox/
44
+ .coverage
45
+ .coverage.*
46
+ .cache
47
+ nosetests.xml
48
+ coverage.xml
49
+ *.cover
50
+ *.py,cover
51
+ .hypothesis/
52
+ .pytest_cache/
53
+ cover/
54
+
55
+ # Translations
56
+ *.mo
57
+ *.pot
58
+
59
+ # Django stuff:
60
+ *.log
61
+ local_settings.py
62
+ db.sqlite3
63
+ db.sqlite3-journal
64
+
65
+ # Flask stuff:
66
+ instance/
67
+ .webassets-cache
68
+
69
+ # Scrapy stuff:
70
+ .scrapy
71
+
72
+ # Sphinx documentation
73
+ docs/_build/
74
+
75
+ # PyBuilder
76
+ .pybuilder/
77
+ target/
78
+
79
+ # Jupyter Notebook
80
+ .ipynb_checkpoints
81
+
82
+ # IPython
83
+ profile_default/
84
+ ipython_config.py
85
+
86
+ # pyenv
87
+ # For a library or package, you might want to ignore these files since the code is
88
+ # intended to run in multiple environments; otherwise, check them in:
89
+ # .python-version
90
+
91
+ # pipenv
92
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
94
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
95
+ # install all needed dependencies.
96
+ #Pipfile.lock
97
+
98
+ # poetry
99
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
100
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
101
+ # commonly ignored for libraries.
102
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
103
+ #poetry.lock
104
+
105
+ # pdm
106
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
107
+ #pdm.lock
108
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
109
+ # in version control.
110
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
111
+ .pdm.toml
112
+ .pdm-python
113
+ .pdm-build/
114
+
115
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
116
+ __pypackages__/
117
+
118
+ # Celery stuff
119
+ celerybeat-schedule
120
+ celerybeat.pid
121
+
122
+ # SageMath parsed files
123
+ *.sage.py
124
+
125
+ # Environments
126
+ .env
127
+ .venv
128
+ env/
129
+ venv/
130
+ ENV/
131
+ env.bak/
132
+ venv.bak/
133
+
134
+ # Spyder project settings
135
+ .spyderproject
136
+ .spyproject
137
+
138
+ # Rope project settings
139
+ .ropeproject
140
+
141
+ # mkdocs documentation
142
+ /site
143
+
144
+ # mypy
145
+ .mypy_cache/
146
+ .dmypy.json
147
+ dmypy.json
148
+
149
+ # Pyre type checker
150
+ .pyre/
151
+
152
+ # pytype static type analyzer
153
+ .pytype/
154
+
155
+ # Cython debug symbols
156
+ cython_debug/
157
+
158
+ # PyCharm
159
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
160
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
161
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
162
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
163
+ #.idea/
app.py CHANGED
@@ -1,45 +1,22 @@
1
  import streamlit as st
2
- from langchain_openai import ChatOpenAI
3
- from langchain_core.prompts import ChatPromptTemplate
4
- from langchain.schema import StrOutputParser
5
-
6
- chat_llm = ChatOpenAI(
7
- openai_api_key=st.secrets["OPENAI_API_KEY"],
8
- model=st.secrets["OPENAI_MODEL"],
9
- )
10
 
11
  caption_examples_file_path = "./data/caption_examples.txt"
12
-
13
- prompt = ChatPromptTemplate.from_messages(
14
- [
15
- (
16
- "system",
17
- "You are a instagram post writer and you writing captions for posts for company that make hiking and bicycle backpacks. Responde with 2 sentence max, use context as example",
18
- ),
19
- ( "system", "{example}" ),
20
- ( "human", "{question}" ),
21
- ]
22
- )
23
-
24
- chat_chain = prompt | chat_llm | StrOutputParser()
25
-
26
  with open(caption_examples_file_path, "r") as file:
27
  caption_examples = file.read()
28
 
29
-
30
  if "visibility" not in st.session_state:
31
  st.session_state.visibility = "visible"
32
  st.session_state.disabled = False
33
  st.session_state.placeholder = "Example: Generate post about backpack Black Mamba with volume of 22 liters"
34
 
35
-
36
  st.set_page_config(
37
- page_title="Backpack title generator",
38
- page_icon="πŸ‘‹",
39
  )
40
- st.write("# Welcome to InstaGPT! πŸ‘‹")
41
- st.markdown("""Writes caption for a desired backpacks in style of Osprey""")
42
 
 
 
43
 
44
  text_input = st.text_input(
45
  "Enter some text πŸ‘‡",
@@ -48,18 +25,19 @@ text_input = st.text_input(
48
  placeholder=st.session_state.placeholder,
49
  )
50
 
51
- predefined_strings = ["Generate post about backpack Black Mamba with volume of 22 liters", "Write a post about giveaway of 3 backpacks from new collection", "Create new post about backpack Adventure for 250 dollars"]
 
 
 
52
 
53
- st.write("Examples: \n\n Generate post about backpack Black Mamba with volume of 22 liters \n\n Write a post about giveaway of 3 backpacks from new collection \n\n Create new post about backpack Adventure for 250 dollars")
54
 
55
- generate_respose = st.button("Generate")
56
  if text_input:
57
- st.write("You entered: ", text_input)
58
 
59
-
60
- if generate_respose:
61
  if text_input == "":
62
- st.write("Enter something")
63
  else:
64
  response = chat_chain.invoke(
65
  {
@@ -67,6 +45,4 @@ if generate_respose:
67
  "question": text_input,
68
  }
69
  )
70
-
71
- st.write("Generated: ", response)
72
-
 
1
  import streamlit as st
2
+ from model import chat_chain
 
 
 
 
 
 
 
3
 
4
  caption_examples_file_path = "./data/caption_examples.txt"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  with open(caption_examples_file_path, "r") as file:
6
  caption_examples = file.read()
7
 
 
8
  if "visibility" not in st.session_state:
9
  st.session_state.visibility = "visible"
10
  st.session_state.disabled = False
11
  st.session_state.placeholder = "Example: Generate post about backpack Black Mamba with volume of 22 liters"
12
 
 
13
  st.set_page_config(
14
+ page_title="Backpack Title Generator",
15
+ page_icon="πŸŽ’"
16
  )
 
 
17
 
18
+ st.write("# Welcome to InstaGPT! πŸ‘‹")
19
+ st.markdown("Write captions for backpacks in the style of Osprey")
20
 
21
  text_input = st.text_input(
22
  "Enter some text πŸ‘‡",
 
25
  placeholder=st.session_state.placeholder,
26
  )
27
 
28
+ st.write("Examples:")
29
+ st.write("Generate post about backpack Black Mamba with volume of 22 liters")
30
+ st.write("Write a post about giveaway of 3 backpacks from new collection")
31
+ st.write("Create new post about backpack Adventure for 250 dollars")
32
 
33
+ generate_response = st.button("Generate")
34
 
 
35
  if text_input:
36
+ st.write("You entered:", text_input)
37
 
38
+ if generate_response:
 
39
  if text_input == "":
40
+ st.write("Please enter some text.")
41
  else:
42
  response = chat_chain.invoke(
43
  {
 
45
  "question": text_input,
46
  }
47
  )
48
+ st.write("Generated:", response)
 
 
model.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain_openai import ChatOpenAI
3
+ from langchain_core.prompts import ChatPromptTemplate
4
+ from langchain.schema import StrOutputParser
5
+
6
+ chat_llm = ChatOpenAI(
7
+ openai_api_key=st.secrets["OPENAI_API_KEY"],
8
+ model=st.secrets["OPENAI_MODEL"],
9
+ )
10
+
11
+
12
+ prompt = ChatPromptTemplate.from_messages(
13
+ [
14
+ (
15
+ "system",
16
+ "You are a instagram post writer and you writing captions for posts for company that make hiking and bicycle backpacks. "
17
+ "Responde with 2 sentence max, use context as example. ",
18
+ ),
19
+ ( "system", "{example}" ),
20
+ ( "human", "{question}" ),
21
+ ]
22
+ )
23
+
24
+ chat_chain = prompt | chat_llm | StrOutputParser()