Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -103,32 +103,32 @@ class JournalCompanion:
|
|
103 |
except ZeroDivisionError:
|
104 |
return "No entries available for analysis."
|
105 |
|
106 |
-
# Rest of the code (create_journal_interface function and CSS) remains the samepad_token_id=tokenizer.eos_token_id
|
107 |
-
|
108 |
def create_journal_interface():
|
109 |
journal = JournalCompanion()
|
110 |
|
111 |
# Custom CSS for better styling
|
112 |
custom_css = """
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
114 |
.container {
|
115 |
max-width: 1200px;
|
116 |
margin: 0 auto;
|
117 |
padding: 20px;
|
118 |
}
|
119 |
-
|
120 |
-
/* Header styles */
|
121 |
.header {
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
}
|
129 |
|
130 |
-
|
131 |
-
/* Input area styles */
|
132 |
.input-container {
|
133 |
background: white;
|
134 |
border-radius: 15px;
|
@@ -136,33 +136,30 @@ def create_journal_interface():
|
|
136 |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
137 |
margin-bottom: 20px;
|
138 |
}
|
139 |
-
|
140 |
-
/* Output area styles */
|
141 |
.output-container {
|
142 |
background: #f8f9fa;
|
143 |
border-radius: 15px;
|
144 |
padding: 20px;
|
145 |
margin-top: 20px;
|
146 |
}
|
147 |
-
|
148 |
-
/* Button styles */
|
149 |
.custom-button {
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
}
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
|
|
163 |
|
164 |
-
|
165 |
-
/* Card styles */
|
166 |
.card {
|
167 |
background: white;
|
168 |
border-radius: 10px;
|
@@ -171,47 +168,37 @@ def create_journal_interface():
|
|
171 |
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
172 |
transition: transform 0.2s;
|
173 |
}
|
174 |
-
|
175 |
.card:hover {
|
176 |
transform: translateY(-2px);
|
177 |
}
|
178 |
-
|
179 |
-
/* Animation for results */
|
180 |
@keyframes fadeIn {
|
181 |
from { opacity: 0; transform: translateY(10px); }
|
182 |
to { opacity: 1; transform: translateY(0); }
|
183 |
}
|
184 |
-
|
185 |
.result-animation {
|
186 |
animation: fadeIn 0.5s ease-out;
|
187 |
}
|
188 |
-
|
189 |
-
/* Responsive design */
|
190 |
@media (max-width: 768px) {
|
191 |
.container {
|
192 |
padding: 10px;
|
193 |
}
|
194 |
-
|
195 |
.header {
|
196 |
padding: 1rem;
|
197 |
}
|
198 |
}
|
199 |
"""
|
200 |
|
201 |
-
|
202 |
with gr.Blocks(css=custom_css, title="AI Journal Companion") as interface:
|
203 |
with gr.Column(elem_classes="container"):
|
204 |
-
# Header
|
205 |
with gr.Column(elem_classes="header"):
|
206 |
gr.Markdown("# π AI Journal Companion")
|
207 |
-
gr.Markdown(
|
208 |
-
"Transform your thoughts into insights with AI-powered journaling",
|
209 |
-
elem_classes="subtitle"
|
210 |
-
)
|
211 |
|
212 |
-
# Main content
|
213 |
with gr.Row():
|
214 |
-
# Input Column
|
215 |
with gr.Column(scale=1, elem_classes="input-container"):
|
216 |
entry_input = gr.Textbox(
|
217 |
label="Write Your Thoughts",
|
@@ -219,54 +206,28 @@ def create_journal_interface():
|
|
219 |
lines=8,
|
220 |
elem_classes="journal-input"
|
221 |
)
|
222 |
-
submit_btn = gr.Button(
|
223 |
-
"β¨ Analyze Entry",
|
224 |
-
variant="primary",
|
225 |
-
elem_classes="custom-button"
|
226 |
-
)
|
227 |
|
228 |
-
# Output Column
|
229 |
with gr.Column(scale=1, elem_classes="output-container"):
|
230 |
with gr.Column(elem_classes="card result-animation"):
|
231 |
result_message = gr.Markdown(label="Analysis")
|
232 |
-
sentiment_output = gr.Textbox(
|
233 |
-
label="Emotional Tone",
|
234 |
-
elem_classes="sentiment-output"
|
235 |
-
)
|
236 |
|
237 |
with gr.Column(elem_classes="card result-animation"):
|
238 |
-
prompt_output = gr.Markdown(
|
239 |
-
label="Reflection Prompts",
|
240 |
-
elem_classes="prompts-output"
|
241 |
-
)
|
242 |
|
243 |
with gr.Column(elem_classes="card result-animation"):
|
244 |
-
affirmation_output = gr.Textbox(
|
245 |
-
label="Your Daily Affirmation",
|
246 |
-
elem_classes="affirmation-output"
|
247 |
-
)
|
248 |
|
249 |
-
# Insights Section
|
250 |
with gr.Row(elem_classes="insights-section"):
|
251 |
with gr.Column(scale=1):
|
252 |
-
insights_btn = gr.Button(
|
253 |
-
|
254 |
-
elem_classes="custom-button"
|
255 |
-
)
|
256 |
-
insights_output = gr.Markdown(
|
257 |
-
elem_classes="card insights-card"
|
258 |
-
)
|
259 |
|
260 |
-
# Event handlers
|
261 |
submit_btn.click(
|
262 |
fn=journal.analyze_entry,
|
263 |
inputs=[entry_input],
|
264 |
-
outputs=[
|
265 |
-
result_message,
|
266 |
-
sentiment_output,
|
267 |
-
prompt_output,
|
268 |
-
affirmation_output
|
269 |
-
]
|
270 |
)
|
271 |
|
272 |
insights_btn.click(
|
@@ -279,4 +240,4 @@ def create_journal_interface():
|
|
279 |
|
280 |
if __name__ == "__main__":
|
281 |
interface = create_journal_interface()
|
282 |
-
interface.launch()
|
|
|
103 |
except ZeroDivisionError:
|
104 |
return "No entries available for analysis."
|
105 |
|
|
|
|
|
106 |
def create_journal_interface():
|
107 |
journal = JournalCompanion()
|
108 |
|
109 |
# Custom CSS for better styling
|
110 |
custom_css = """
|
111 |
+
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');
|
112 |
+
|
113 |
+
* {
|
114 |
+
font-family: 'Roboto', sans-serif;
|
115 |
+
}
|
116 |
+
|
117 |
.container {
|
118 |
max-width: 1200px;
|
119 |
margin: 0 auto;
|
120 |
padding: 20px;
|
121 |
}
|
122 |
+
|
|
|
123 |
.header {
|
124 |
+
text-align: center;
|
125 |
+
margin-bottom: 2rem;
|
126 |
+
background: linear-gradient(135deg, #2196f3 0%, #26c6da 100%);
|
127 |
+
padding: 2rem;
|
128 |
+
border-radius: 15px;
|
129 |
+
color: #ffffff;
|
130 |
+
}
|
131 |
|
|
|
|
|
132 |
.input-container {
|
133 |
background: white;
|
134 |
border-radius: 15px;
|
|
|
136 |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
137 |
margin-bottom: 20px;
|
138 |
}
|
139 |
+
|
|
|
140 |
.output-container {
|
141 |
background: #f8f9fa;
|
142 |
border-radius: 15px;
|
143 |
padding: 20px;
|
144 |
margin-top: 20px;
|
145 |
}
|
146 |
+
|
|
|
147 |
.custom-button {
|
148 |
+
background: linear-gradient(135deg, #009688 0%, #0072ff 100%);
|
149 |
+
border: none;
|
150 |
+
padding: 10px 20px;
|
151 |
+
border-radius: 8px;
|
152 |
+
color: white;
|
153 |
+
font-weight: bold;
|
154 |
+
cursor: pointer;
|
155 |
+
transition: transform 0.2s, box-shadow 0.2s;
|
156 |
+
}
|
157 |
+
|
158 |
+
.custom-button:hover {
|
159 |
+
transform: translateY(-2px);
|
160 |
+
box-shadow: 0 4px 8px rgba(0, 114, 255, 0.4);
|
161 |
+
}
|
162 |
|
|
|
|
|
163 |
.card {
|
164 |
background: white;
|
165 |
border-radius: 10px;
|
|
|
168 |
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
169 |
transition: transform 0.2s;
|
170 |
}
|
171 |
+
|
172 |
.card:hover {
|
173 |
transform: translateY(-2px);
|
174 |
}
|
175 |
+
|
|
|
176 |
@keyframes fadeIn {
|
177 |
from { opacity: 0; transform: translateY(10px); }
|
178 |
to { opacity: 1; transform: translateY(0); }
|
179 |
}
|
180 |
+
|
181 |
.result-animation {
|
182 |
animation: fadeIn 0.5s ease-out;
|
183 |
}
|
184 |
+
|
|
|
185 |
@media (max-width: 768px) {
|
186 |
.container {
|
187 |
padding: 10px;
|
188 |
}
|
|
|
189 |
.header {
|
190 |
padding: 1rem;
|
191 |
}
|
192 |
}
|
193 |
"""
|
194 |
|
|
|
195 |
with gr.Blocks(css=custom_css, title="AI Journal Companion") as interface:
|
196 |
with gr.Column(elem_classes="container"):
|
|
|
197 |
with gr.Column(elem_classes="header"):
|
198 |
gr.Markdown("# π AI Journal Companion")
|
199 |
+
gr.Markdown("Transform your thoughts into insights with AI-powered journaling", elem_classes="subtitle")
|
|
|
|
|
|
|
200 |
|
|
|
201 |
with gr.Row():
|
|
|
202 |
with gr.Column(scale=1, elem_classes="input-container"):
|
203 |
entry_input = gr.Textbox(
|
204 |
label="Write Your Thoughts",
|
|
|
206 |
lines=8,
|
207 |
elem_classes="journal-input"
|
208 |
)
|
209 |
+
submit_btn = gr.Button("β¨ Analyze Entry", variant="primary", elem_classes="custom-button")
|
|
|
|
|
|
|
|
|
210 |
|
|
|
211 |
with gr.Column(scale=1, elem_classes="output-container"):
|
212 |
with gr.Column(elem_classes="card result-animation"):
|
213 |
result_message = gr.Markdown(label="Analysis")
|
214 |
+
sentiment_output = gr.Textbox(label="Emotional Tone", elem_classes="sentiment-output")
|
|
|
|
|
|
|
215 |
|
216 |
with gr.Column(elem_classes="card result-animation"):
|
217 |
+
prompt_output = gr.Markdown(label="Reflection Prompts", elem_classes="prompts-output")
|
|
|
|
|
|
|
218 |
|
219 |
with gr.Column(elem_classes="card result-animation"):
|
220 |
+
affirmation_output = gr.Textbox(label="Your Daily Affirmation", elem_classes="affirmation-output")
|
|
|
|
|
|
|
221 |
|
|
|
222 |
with gr.Row(elem_classes="insights-section"):
|
223 |
with gr.Column(scale=1):
|
224 |
+
insights_btn = gr.Button("π View Monthly Insights", elem_classes="custom-button")
|
225 |
+
insights_output = gr.Markdown(elem_classes="card insights-card")
|
|
|
|
|
|
|
|
|
|
|
226 |
|
|
|
227 |
submit_btn.click(
|
228 |
fn=journal.analyze_entry,
|
229 |
inputs=[entry_input],
|
230 |
+
outputs=[result_message, sentiment_output, prompt_output, affirmation_output]
|
|
|
|
|
|
|
|
|
|
|
231 |
)
|
232 |
|
233 |
insights_btn.click(
|
|
|
240 |
|
241 |
if __name__ == "__main__":
|
242 |
interface = create_journal_interface()
|
243 |
+
interface.launch()
|