Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- __pycache__/app.cpython-310.pyc +0 -0
- app.py +28 -2
- deploy_gradio_demo.sh +3 -1
- requirements.txt +1 -0
__pycache__/app.cpython-310.pyc
CHANGED
Binary files a/__pycache__/app.cpython-310.pyc and b/__pycache__/app.cpython-310.pyc differ
|
|
app.py
CHANGED
@@ -4,6 +4,8 @@ from io import BytesIO
|
|
4 |
from openai import OpenAI
|
5 |
import gradio as gr
|
6 |
import base64
|
|
|
|
|
7 |
from dotenv import load_dotenv
|
8 |
load_dotenv()
|
9 |
|
@@ -30,6 +32,15 @@ with demo:
|
|
30 |
info='Please provide product details and features.'
|
31 |
)
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
with gr.Row():
|
34 |
length = gr.Number(label='Length (words)', value=50)
|
35 |
|
@@ -89,7 +100,7 @@ with demo:
|
|
89 |
with gr.Group():
|
90 |
output = gr.HTML()
|
91 |
|
92 |
-
gr.Markdown('Version 0.0.
|
93 |
|
94 |
gpt_model = 'gpt-4-0125-preview' # 'gpt-3.5-turbo' 'gpt-4-vision-preview'
|
95 |
|
@@ -111,14 +122,18 @@ with demo:
|
|
111 |
target_audience,
|
112 |
core_message,
|
113 |
product_details,
|
|
|
114 |
length,
|
115 |
tone,
|
116 |
channel,
|
|
|
117 |
# img=None
|
118 |
):
|
119 |
|
120 |
# img_b64 = img_to_b64(img)
|
121 |
|
|
|
|
|
122 |
messages = [
|
123 |
{
|
124 |
'role': 'system',
|
@@ -136,7 +151,8 @@ with demo:
|
|
136 |
PRODUCT_DETAILS:{product_details},
|
137 |
LENGTH: {length} words,
|
138 |
TONE:{tone},
|
139 |
-
AVERTISING_CHANNEL:{channel}
|
|
|
140 |
'''
|
141 |
},
|
142 |
|
@@ -164,6 +180,14 @@ with demo:
|
|
164 |
</p>
|
165 |
''')
|
166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
submit_btn.click(
|
168 |
submit_text,
|
169 |
[
|
@@ -171,9 +195,11 @@ with demo:
|
|
171 |
target_audience,
|
172 |
core_message,
|
173 |
product_details,
|
|
|
174 |
length,
|
175 |
tone,
|
176 |
channel,
|
|
|
177 |
],
|
178 |
[output])
|
179 |
|
|
|
4 |
from openai import OpenAI
|
5 |
import gradio as gr
|
6 |
import base64
|
7 |
+
import textract
|
8 |
+
|
9 |
from dotenv import load_dotenv
|
10 |
load_dotenv()
|
11 |
|
|
|
32 |
info='Please provide product details and features.'
|
33 |
)
|
34 |
|
35 |
+
product_document = gr.File(
|
36 |
+
label='Product Document'
|
37 |
+
)
|
38 |
+
|
39 |
+
content_restrictions = gr.Textbox(
|
40 |
+
label='Content Restrictions',
|
41 |
+
info='Use phrases like "Do not ... ..." to enforce model behavior.'
|
42 |
+
)
|
43 |
+
|
44 |
with gr.Row():
|
45 |
length = gr.Number(label='Length (words)', value=50)
|
46 |
|
|
|
100 |
with gr.Group():
|
101 |
output = gr.HTML()
|
102 |
|
103 |
+
gr.Markdown('Version 0.0.1 | Updated: 2024-Mar-29')
|
104 |
|
105 |
gpt_model = 'gpt-4-0125-preview' # 'gpt-3.5-turbo' 'gpt-4-vision-preview'
|
106 |
|
|
|
122 |
target_audience,
|
123 |
core_message,
|
124 |
product_details,
|
125 |
+
product_document,
|
126 |
length,
|
127 |
tone,
|
128 |
channel,
|
129 |
+
content_restrictions,
|
130 |
# img=None
|
131 |
):
|
132 |
|
133 |
# img_b64 = img_to_b64(img)
|
134 |
|
135 |
+
product_details = product_details + read_doc_file(product_document)
|
136 |
+
|
137 |
messages = [
|
138 |
{
|
139 |
'role': 'system',
|
|
|
151 |
PRODUCT_DETAILS:{product_details},
|
152 |
LENGTH: {length} words,
|
153 |
TONE:{tone},
|
154 |
+
AVERTISING_CHANNEL:{channel},
|
155 |
+
CONTENT_RESTRICTIONS:{content_restrictions}
|
156 |
'''
|
157 |
},
|
158 |
|
|
|
180 |
</p>
|
181 |
''')
|
182 |
|
183 |
+
def read_doc_file(file):
|
184 |
+
try:
|
185 |
+
doc_text = textract.process(file)
|
186 |
+
except Exception:
|
187 |
+
return ''
|
188 |
+
|
189 |
+
return doc_text.decode("utf-8")
|
190 |
+
|
191 |
submit_btn.click(
|
192 |
submit_text,
|
193 |
[
|
|
|
195 |
target_audience,
|
196 |
core_message,
|
197 |
product_details,
|
198 |
+
product_document,
|
199 |
length,
|
200 |
tone,
|
201 |
channel,
|
202 |
+
content_restrictions,
|
203 |
],
|
204 |
[output])
|
205 |
|
deploy_gradio_demo.sh
CHANGED
@@ -10,7 +10,9 @@ if [ $response = "y" ]; then
|
|
10 |
echo 'Deploying ...'
|
11 |
|
12 |
# Store .env content to local variable
|
13 |
-
env_value=$(
|
|
|
|
|
14 |
|
15 |
# Remove .env file, because it will be publish to gradio
|
16 |
rm .env || echo 'no .env found'
|
|
|
10 |
echo 'Deploying ...'
|
11 |
|
12 |
# Store .env content to local variable
|
13 |
+
env_value=$(cat .env)
|
14 |
+
|
15 |
+
echo "$env_value"
|
16 |
|
17 |
# Remove .env file, because it will be publish to gradio
|
18 |
rm .env || echo 'no .env found'
|
requirements.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
pillow
|
2 |
python-dotenv
|
3 |
openai
|
|
|
|
1 |
pillow
|
2 |
python-dotenv
|
3 |
openai
|
4 |
+
textract
|