Update app.py
Browse files
app.py
CHANGED
@@ -84,50 +84,69 @@ print("Processing PDF ingestion from directory:", PDF_DIRECTORY)
|
|
84 |
data_ingestion_from_directory()
|
85 |
|
86 |
# Define the function to handle predictions
|
87 |
-
def predict(message,history):
|
88 |
response = handle_query(message)
|
89 |
-
return response
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
-
#
|
93 |
css = '''
|
94 |
-
/* Style the chat container */
|
95 |
.gradio-container {
|
96 |
display: flex;
|
97 |
flex-direction: column;
|
98 |
-
width:
|
|
|
99 |
margin: 0 auto;
|
100 |
padding: 20px;
|
101 |
border: 1px solid #ddd;
|
102 |
border-radius: 10px;
|
103 |
background-color: #fff;
|
104 |
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
|
105 |
-
|
106 |
-
height: 600px;
|
107 |
}
|
108 |
-
|
109 |
-
/* Style the logo */
|
110 |
.gradio-logo {
|
111 |
-
|
112 |
-
justify-content: center;
|
113 |
margin-bottom: 20px;
|
114 |
}
|
115 |
-
|
116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
width: 100%;
|
118 |
-
|
|
|
119 |
}
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
}
|
129 |
-
|
130 |
-
/* Style the chat history */
|
131 |
.gradio-chat-history {
|
132 |
flex: 1;
|
133 |
overflow-y: auto;
|
@@ -136,16 +155,13 @@ css = '''
|
|
136 |
background-color: #f9f9f9;
|
137 |
border-radius: 5px;
|
138 |
margin-bottom: 10px;
|
139 |
-
max-height: 500px;
|
140 |
}
|
141 |
-
|
142 |
-
/* Style the chat messages */
|
143 |
.gradio-message {
|
144 |
margin-bottom: 15px;
|
145 |
display: flex;
|
146 |
-
flex-direction: column;
|
147 |
}
|
148 |
-
|
149 |
.gradio-message.user .gradio-message-content {
|
150 |
background-color: #E1FFC7;
|
151 |
align-self: flex-end;
|
@@ -156,7 +172,6 @@ css = '''
|
|
156 |
margin-bottom: 5px;
|
157 |
max-width: 80%;
|
158 |
}
|
159 |
-
|
160 |
.gradio-message.bot .gradio-message-content {
|
161 |
background-color: #fff;
|
162 |
align-self: flex-start;
|
@@ -167,45 +182,35 @@ css = '''
|
|
167 |
margin-bottom: 5px;
|
168 |
max-width: 80%;
|
169 |
}
|
170 |
-
|
171 |
-
.gradio-message-content {
|
172 |
-
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
173 |
-
}
|
174 |
-
|
175 |
-
/* Style the footer */
|
176 |
.gradio-footer {
|
177 |
display: flex;
|
178 |
padding: 10px;
|
179 |
border-top: 1px solid #ddd;
|
180 |
-
background-color: #F8D7DA;
|
181 |
position: absolute;
|
182 |
bottom: 0;
|
183 |
-
width: calc(100% - 40px);
|
184 |
}
|
185 |
-
|
186 |
-
/* Remove Gradio footer */
|
187 |
footer {
|
188 |
display: none !important;
|
189 |
background-color: #F8D7DA;
|
190 |
}
|
|
|
|
|
|
|
191 |
'''
|
192 |
|
193 |
-
# Create a custom HTML block for the logo
|
194 |
logo_html = '''
|
195 |
<div class="gradio-logo">
|
196 |
-
<img src="
|
197 |
</div>
|
198 |
'''
|
199 |
|
200 |
-
# Create
|
201 |
-
with gr.Blocks(theme=gr.themes.Monochrome(), fill_height=True,css=css) as demo:
|
202 |
-
gr.
|
203 |
-
|
204 |
-
|
205 |
-
retry_btn=None)
|
206 |
|
207 |
# Launch the interface
|
208 |
-
demo.launch()
|
209 |
-
|
210 |
-
|
211 |
-
|
|
|
84 |
data_ingestion_from_directory()
|
85 |
|
86 |
# Define the function to handle predictions
|
87 |
+
"""def predict(message,history):
|
88 |
response = handle_query(message)
|
89 |
+
return response"""
|
90 |
+
def predict(message, history):
|
91 |
+
logo_html = '''
|
92 |
+
<div class="circle-logo">
|
93 |
+
<img src="1.jpeg" alt="FernAi">
|
94 |
+
</div>
|
95 |
+
'''
|
96 |
+
response = handle_query(message)
|
97 |
+
response_with_logo = f'<div class="response-with-logo">{logo_html}<div class="response-text">{response}</div></div>'
|
98 |
+
return response_with_logo
|
99 |
|
100 |
+
# Custom CSS for styling
|
101 |
css = '''
|
|
|
102 |
.gradio-container {
|
103 |
display: flex;
|
104 |
flex-direction: column;
|
105 |
+
width: 100%;
|
106 |
+
max-width: 450px;
|
107 |
margin: 0 auto;
|
108 |
padding: 20px;
|
109 |
border: 1px solid #ddd;
|
110 |
border-radius: 10px;
|
111 |
background-color: #fff;
|
112 |
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
|
113 |
+
height: 100%;
|
114 |
+
max-height: 600px;
|
115 |
}
|
|
|
|
|
116 |
.gradio-logo {
|
117 |
+
text-align: center;
|
|
|
118 |
margin-bottom: 20px;
|
119 |
}
|
120 |
+
.circle-logo {
|
121 |
+
display: inline-block;
|
122 |
+
width: 40px;
|
123 |
+
height: 40px;
|
124 |
+
border-radius: 50%;
|
125 |
+
overflow: hidden;
|
126 |
+
margin-right: 10px;
|
127 |
+
vertical-align: middle;
|
128 |
+
}
|
129 |
+
.circle-logo img {
|
130 |
width: 100%;
|
131 |
+
height: 100%;
|
132 |
+
object-fit: cover;
|
133 |
}
|
134 |
+
.response-with-logo {
|
135 |
+
display: flex;
|
136 |
+
align-items: center;
|
137 |
+
margin-bottom: 10px;
|
138 |
+
}
|
139 |
+
.response-text {
|
140 |
+
display: inline-block;
|
141 |
+
vertical-align: middle;
|
142 |
+
font-size: 16px;
|
143 |
+
background-color: #fff;
|
144 |
+
border: 1px solid #ced4da;
|
145 |
+
border-radius: 15px 15px 15px 0;
|
146 |
+
padding: 10px;
|
147 |
+
max-width: 80%;
|
148 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
149 |
}
|
|
|
|
|
150 |
.gradio-chat-history {
|
151 |
flex: 1;
|
152 |
overflow-y: auto;
|
|
|
155 |
background-color: #f9f9f9;
|
156 |
border-radius: 5px;
|
157 |
margin-bottom: 10px;
|
158 |
+
max-height: 500px;
|
159 |
}
|
|
|
|
|
160 |
.gradio-message {
|
161 |
margin-bottom: 15px;
|
162 |
display: flex;
|
163 |
+
flex-direction: column;
|
164 |
}
|
|
|
165 |
.gradio-message.user .gradio-message-content {
|
166 |
background-color: #E1FFC7;
|
167 |
align-self: flex-end;
|
|
|
172 |
margin-bottom: 5px;
|
173 |
max-width: 80%;
|
174 |
}
|
|
|
175 |
.gradio-message.bot .gradio-message-content {
|
176 |
background-color: #fff;
|
177 |
align-self: flex-start;
|
|
|
182 |
margin-bottom: 5px;
|
183 |
max-width: 80%;
|
184 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
.gradio-footer {
|
186 |
display: flex;
|
187 |
padding: 10px;
|
188 |
border-top: 1px solid #ddd;
|
189 |
+
background-color: #F8D7DA;
|
190 |
position: absolute;
|
191 |
bottom: 0;
|
192 |
+
width: calc(100% - 40px);
|
193 |
}
|
|
|
|
|
194 |
footer {
|
195 |
display: none !important;
|
196 |
background-color: #F8D7DA;
|
197 |
}
|
198 |
+
.gradio-chat-history .gradio-message.bot .gradio-message-content::before {
|
199 |
+
content: none;
|
200 |
+
}
|
201 |
'''
|
202 |
|
|
|
203 |
logo_html = '''
|
204 |
<div class="gradio-logo">
|
205 |
+
<img src="2.png" alt="FernAi" style="display: block; margin: 0 auto; width: 100px; height: 100px;">
|
206 |
</div>
|
207 |
'''
|
208 |
|
209 |
+
# Create the Blocks layout with the custom HTML and ChatInterface
|
210 |
+
with gr.Blocks(theme=gr.themes.Monochrome(), fill_height=True, css=css) as demo:
|
211 |
+
with gr.Column():
|
212 |
+
gr.HTML(logo_html)
|
213 |
+
gr.ChatInterface(predict, clear_btn=None, undo_btn=None, retry_btn=None)
|
|
|
214 |
|
215 |
# Launch the interface
|
216 |
+
demo.launch()
|
|
|
|
|
|