Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -139,6 +139,27 @@ personalized_data = fetch_personalized_data()
|
|
| 139 |
# Print or use the json_result variable as needed
|
| 140 |
print(personalized_data)
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
def store_message(name: str, message: str):
|
| 144 |
if name and message:
|
|
@@ -150,8 +171,22 @@ def store_message(name: str, message: str):
|
|
| 150 |
commit_url = repo.push_to_hub()
|
| 151 |
return generate_html()
|
| 152 |
|
| 153 |
-
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
|
| 157 |
'''
|
|
|
|
| 139 |
# Print or use the json_result variable as needed
|
| 140 |
print(personalized_data)
|
| 141 |
|
| 142 |
+
demo.launch()
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def generate_html() -> str:
|
| 146 |
+
with open(DATA_FILE) as csvfile:
|
| 147 |
+
reader = csv.DictReader(csvfile)
|
| 148 |
+
rows = []
|
| 149 |
+
for row in reader:
|
| 150 |
+
rows.append(row)
|
| 151 |
+
rows.reverse()
|
| 152 |
+
if len(rows) == 0:
|
| 153 |
+
return "no messages yet"
|
| 154 |
+
else:
|
| 155 |
+
html = "<div class='chatbot'>"
|
| 156 |
+
for row in rows:
|
| 157 |
+
html += "<div>"
|
| 158 |
+
html += f"<span>{row['name']}</span>"
|
| 159 |
+
html += f"<span class='message'>{row['message']}</span>"
|
| 160 |
+
html += "</div>"
|
| 161 |
+
html += "</div>"
|
| 162 |
+
return html
|
| 163 |
|
| 164 |
def store_message(name: str, message: str):
|
| 165 |
if name and message:
|
|
|
|
| 171 |
commit_url = repo.push_to_hub()
|
| 172 |
return generate_html()
|
| 173 |
|
| 174 |
+
iface = gr.Interface(
|
| 175 |
+
store_message,
|
| 176 |
+
[
|
| 177 |
+
inputs.Textbox(placeholder="Your name"),
|
| 178 |
+
inputs.Textbox(placeholder="Your message", lines=2),
|
| 179 |
+
],
|
| 180 |
+
"html",
|
| 181 |
+
css="""
|
| 182 |
+
.message {background-color:cornflowerblue;color:white; padding:4px;margin:4px;border-radius:4px; }
|
| 183 |
+
""",
|
| 184 |
+
title="Reading/writing to a HuggingFace dataset repo from Spaces",
|
| 185 |
+
description=f"This is a demo of how to do simple *shared data persistence* in a Gradio Space, backed by a dataset repo.",
|
| 186 |
+
article=f"The dataset repo is [{DATASET_REPO_URL}]({DATASET_REPO_URL})",
|
| 187 |
+
)
|
| 188 |
+
|
| 189 |
+
iface.launch()
|
| 190 |
|
| 191 |
|
| 192 |
'''
|