Spaces:
Build error
Build error
contenteaseAI
commited on
Commit
•
248cbe2
1
Parent(s):
8eb205c
Update app.py
Browse files
app.py
CHANGED
@@ -2,31 +2,13 @@ import gradio as gr
|
|
2 |
from openai import OpenAI
|
3 |
import os
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
LICENSE = """
|
12 |
-
<p/>
|
13 |
-
---
|
14 |
-
For more information, visit our [website](https://contentease.ai).
|
15 |
-
"""
|
16 |
-
|
17 |
-
PLACEHOLDER = """
|
18 |
-
<div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
|
19 |
-
<h1 style="font-size: 28px; margin-bottom: 2px; opacity: 0.55;">ContenteaseAI Custom AI trained model</h1>
|
20 |
-
<p style="font-size: 18px; margin-bottom: 2px; opacity: 0.65;">Enter the text extracted from the PDF:</p>
|
21 |
-
</div>
|
22 |
-
"""
|
23 |
-
|
24 |
-
css = """
|
25 |
-
h1 {
|
26 |
-
text-align: center;
|
27 |
-
display: block;
|
28 |
}
|
29 |
-
|
30 |
|
31 |
ACCESS_TOKEN = os.getenv("HF_TOKEN")
|
32 |
|
@@ -38,32 +20,72 @@ client = OpenAI(
|
|
38 |
def respond(
|
39 |
message,
|
40 |
history,
|
41 |
-
max_tokens,
|
42 |
temperature,
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
...
|
53 |
-
|
54 |
-
"Area Type2": {
|
55 |
-
"Furniture1",
|
56 |
-
"Furniture2",
|
57 |
...
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
if len(history) == 0:
|
63 |
pass
|
64 |
else:
|
65 |
history.pop()
|
66 |
-
|
67 |
for val in history:
|
68 |
if val[0]:
|
69 |
messages.append({"role": "user", "content": val[0]})
|
@@ -86,14 +108,53 @@ def respond(
|
|
86 |
response += token
|
87 |
yield response
|
88 |
|
89 |
-
demo = gr.ChatInterface(
|
90 |
-
respond,
|
91 |
-
additional_inputs=[
|
92 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
93 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
if __name__ == "__main__":
|
99 |
-
|
|
|
|
|
|
|
|
2 |
from openai import OpenAI
|
3 |
import os
|
4 |
|
5 |
+
css = '''
|
6 |
+
.gradio-container{max-width: 1000px !important}
|
7 |
+
h1{text-align:center}
|
8 |
+
footer {
|
9 |
+
visibility: hidden
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
}
|
11 |
+
'''
|
12 |
|
13 |
ACCESS_TOKEN = os.getenv("HF_TOKEN")
|
14 |
|
|
|
20 |
def respond(
|
21 |
message,
|
22 |
history,
|
|
|
23 |
temperature,
|
24 |
+
max_tokens,
|
25 |
+
):
|
26 |
+
SYS_PROMPT = """
|
27 |
+
Extract all relevant keywords and add quantities from the following text and format the result in nested JSON, ignoring personal details and focusing only on the area and furniture items as shown in the example. Each item should have a count, which will be set to 1 for simplicity. The response should be in JSON format only, without any additional comments.
|
28 |
+
Good JSON example:{
|
29 |
+
"Lobby Area/Entrance": {
|
30 |
+
"Vinyl wall covering": 1,
|
31 |
+
"Decorative hardwired lighting": 1
|
32 |
+
},
|
33 |
+
"Lobby": {
|
34 |
+
"Carpet, carpet pad, and base": 1,
|
35 |
+
"Window treatments": 1,
|
36 |
+
"Artwork and decorative accessories": 1,
|
37 |
+
"Portable lighting": 1,
|
38 |
+
"Upholstered furniture and decorative pillows": 1,
|
39 |
+
"Millwork": 1
|
40 |
+
}
|
41 |
+
}
|
42 |
+
Make sure to fetch details from the provided text and ignore unnecessary information. The response should be in JSON format only, without any additional comments.
|
43 |
+
Task:
|
44 |
+
Convert the provided extracted text into the JSON format described above.
|
45 |
+
Provided Text:
|
46 |
+
PROPERTY IMPROVEMENT PLAN
|
47 |
+
PREPARED FOR:
|
48 |
+
Springfield, IL
|
49 |
+
To be relicensed as Hilton Garden Inn
|
50 |
...
|
51 |
+
Patios/The Terrace - Install patio decorative lighting. Install patio furniture. (lounge chairs, chaise, dining tables/chairs)
|
|
|
|
|
|
|
52 |
...
|
53 |
+
Lobby Area - Replace carpet, carpet pad, and base. Replace window treatments. Replace artwork and decorative accessories. Replace portable lighting. (floor lamps, table lamps) Replace upholstered furniture and decorative pillows. Replace millwork. Replace the television(s).
|
54 |
+
...
|
55 |
+
Registration Area - Replace vinyl wall covering. Replace hard surface floor covering. Replace artwork. Install new signature graphics on the back wall.
|
56 |
+
...
|
57 |
+
Expected Output (JSON format):
|
58 |
+
{
|
59 |
+
"Patios/The Terrace": {
|
60 |
+
"Patio decorative lighting": 1,
|
61 |
+
"Lounge chairs": 1,
|
62 |
+
"Chaise": 1,
|
63 |
+
"Dining tables": 1,
|
64 |
+
"Dining chairs": 1,
|
65 |
+
"Patio furniture": 1
|
66 |
+
},
|
67 |
+
"Lobby Area": {
|
68 |
+
"Carpet, carpet pad, and base": 1,
|
69 |
+
"Window treatments": 1,
|
70 |
+
"Artwork and decorative accessories": 1,
|
71 |
+
"Portable lighting (floor lamps, table lamps)": 1,
|
72 |
+
"Upholstered furniture and decorative pillows": 1,
|
73 |
+
"Millwork": 1,
|
74 |
+
"Television(s)": 1
|
75 |
+
},
|
76 |
+
"Registration Area": {
|
77 |
+
"Vinyl wall covering": 1,
|
78 |
+
"Hard surface floor covering": 1,
|
79 |
+
"Artwork (new signature graphics on the back wall)": 1
|
80 |
+
}
|
81 |
+
}
|
82 |
+
"""
|
83 |
+
messages = [{"role": "system", "content": SYS_PROMPT}]
|
84 |
if len(history) == 0:
|
85 |
pass
|
86 |
else:
|
87 |
history.pop()
|
88 |
+
|
89 |
for val in history:
|
90 |
if val[0]:
|
91 |
messages.append({"role": "user", "content": val[0]})
|
|
|
108 |
response += token
|
109 |
yield response
|
110 |
|
|
|
|
|
|
|
|
|
|
|
111 |
|
112 |
+
DESCRIPTION = '''
|
113 |
+
<div>
|
114 |
+
<h1 style="text-align: center;">ContenteaseAI custom trained model</h1>
|
115 |
+
</div>
|
116 |
+
'''
|
117 |
+
|
118 |
+
LICENSE = """
|
119 |
+
<p/>
|
120 |
+
---
|
121 |
+
For more information, visit our [website](https://contentease.ai).
|
122 |
+
"""
|
123 |
+
|
124 |
+
PLACEHOLDER = """
|
125 |
+
<div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
|
126 |
+
<h1 style="font-size: 28px; margin-bottom: 2px; opacity: 0.55;">ContenteaseAI Custom AI trained model</h1>
|
127 |
+
<p style="font-size: 18px; margin-bottom: 2px; opacity: 0.65;">Enter the text extracted from the PDF:</p>
|
128 |
+
</div>
|
129 |
+
"""
|
130 |
+
|
131 |
+
css = """
|
132 |
+
h1 {
|
133 |
+
text-align: center;
|
134 |
+
display: block;
|
135 |
+
}
|
136 |
+
"""
|
137 |
+
|
138 |
+
chatbot = gr.Chatbot(height=450, placeholder=PLACEHOLDER, label='Gradio ChatInterface')
|
139 |
+
|
140 |
+
with gr.Blocks(fill_height=True, css=css) as demo:
|
141 |
+
gr.Markdown(DESCRIPTION)
|
142 |
+
|
143 |
+
gr.ChatInterface(
|
144 |
+
fn=respond,
|
145 |
+
chatbot=chatbot,
|
146 |
+
fill_height=True,
|
147 |
+
additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
|
148 |
+
additional_inputs=[
|
149 |
+
gr.Slider(minimum=0, maximum=1, step=0.1, value=0.9, label="Temperature", render=False),
|
150 |
+
gr.Slider(minimum=128, maximum=2000, step=1, value=2000, label="Max new tokens", render=False),
|
151 |
+
]
|
152 |
+
)
|
153 |
+
|
154 |
+
gr.Markdown(LICENSE)
|
155 |
+
|
156 |
if __name__ == "__main__":
|
157 |
+
try:
|
158 |
+
demo.launch(show_error=True, debug = True)
|
159 |
+
except Exception as e:
|
160 |
+
logger.error(f"Error launching Gradio demo: {e}")
|