Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,9 +17,11 @@ import fastapi
|
|
| 17 |
from typing import List, Dict
|
| 18 |
import httpx
|
| 19 |
import pandas as pd
|
|
|
|
| 20 |
|
| 21 |
# -------------------------------------------- For Memory - you will need to set up a dataset and HF_TOKEN ---------
|
| 22 |
-
UseMemory=False
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
DATASET_REPO_URL="https://huggingface.co/datasets/awacke1/ChatbotMemory.csv"
|
|
@@ -54,6 +56,7 @@ def store_message(name: str, message: str):
|
|
| 54 |
writer.writerow(
|
| 55 |
{"time": str(datetime.now()), "message": message.strip(), "name": name.strip() }
|
| 56 |
)
|
|
|
|
| 57 |
commit_url = repo.push_to_hub()
|
| 58 |
|
| 59 |
# test api retrieval of any dataset that is saved, then return it...
|
|
@@ -103,21 +106,50 @@ def chat(message, history):
|
|
| 103 |
history_useful = add_note_to_history(response, history_useful)
|
| 104 |
list_history = history_useful[0].split('</s> <s>')
|
| 105 |
history.append((list_history[-2], list_history[-1]))
|
| 106 |
-
|
|
|
|
| 107 |
|
| 108 |
if UseMemory:
|
| 109 |
store_message(message, response) # Save to dataset -- uncomment with code above, create a dataset to store and add your HF_TOKEN from profile to this repo to use.
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
-
gr.
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
#
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
article=f"The memory dataset for saves is [{DATASET_REPO_URL}]({DATASET_REPO_URL}) And here: https://huggingface.co/spaces/awacke1/DatasetAnalyzer Code and datasets on chat are here hf tk: https://paperswithcode.com/datasets?q=chat&v=lst&o=newest"
|
| 123 |
-
).launch(debug=True)
|
|
|
|
| 17 |
from typing import List, Dict
|
| 18 |
import httpx
|
| 19 |
import pandas as pd
|
| 20 |
+
import datasets as ds
|
| 21 |
|
| 22 |
# -------------------------------------------- For Memory - you will need to set up a dataset and HF_TOKEN ---------
|
| 23 |
+
#UseMemory=False
|
| 24 |
+
UseMemory=True
|
| 25 |
|
| 26 |
|
| 27 |
DATASET_REPO_URL="https://huggingface.co/datasets/awacke1/ChatbotMemory.csv"
|
|
|
|
| 56 |
writer.writerow(
|
| 57 |
{"time": str(datetime.now()), "message": message.strip(), "name": name.strip() }
|
| 58 |
)
|
| 59 |
+
#repo.git_pull(rebase=True)
|
| 60 |
commit_url = repo.push_to_hub()
|
| 61 |
|
| 62 |
# test api retrieval of any dataset that is saved, then return it...
|
|
|
|
| 106 |
history_useful = add_note_to_history(response, history_useful)
|
| 107 |
list_history = history_useful[0].split('</s> <s>')
|
| 108 |
history.append((list_history[-2], list_history[-1]))
|
| 109 |
+
|
| 110 |
+
df=pd.DataFrame()
|
| 111 |
|
| 112 |
if UseMemory:
|
| 113 |
store_message(message, response) # Save to dataset -- uncomment with code above, create a dataset to store and add your HF_TOKEN from profile to this repo to use.
|
| 114 |
+
df = ds.load_dataset("awacke1/ChatbotMemory.csv")
|
| 115 |
+
df = df["train"].to_pandas()
|
| 116 |
+
df = df.sort_values(by="time",ascending=False)
|
| 117 |
+
#df.sort_index(axis=1, ascending=False)
|
| 118 |
+
return history, df
|
| 119 |
+
#return df
|
| 120 |
+
#return history, df
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
#gr.Interface(
|
| 124 |
+
# fn=chat,
|
| 125 |
+
# theme="huggingface",
|
| 126 |
+
# css=".footer {display:none !important}",
|
| 127 |
+
# inputs=["text", "state"],
|
| 128 |
+
# #outputs=["chatbot", "state", "text"],
|
| 129 |
+
# outputs=["chatbot", "state", "dataframe"],
|
| 130 |
+
# title=title,
|
| 131 |
+
# allow_flagging="never",
|
| 132 |
+
# description=f"Gradio chatbot backed by memory in a dataset repository.",
|
| 133 |
+
# article=f"The memory dataset for saves is [{DATASET_REPO_URL}]({DATASET_REPO_URL}) And here: https://huggingface.co/spaces/awacke1/DatasetAnalyzer Code and datasets on chat are here hf tk: https://paperswithcode.com/datasets?q=chat&v=lst&o=newest"
|
| 134 |
+
# ).launch(debug=True)
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
with gr.Blocks() as demo:
|
| 139 |
+
gr.Markdown("<h1><center>🍰Gradio chatbot backed by memory in a dataset repository.🎨</center></h1>")
|
| 140 |
+
#gr.Markdown("The memory dataset for saves is [{DATASET_REPO_URL}]({DATASET_REPO_URL}) And here: https://huggingface.co/spaces/awacke1/DatasetAnalyzer Code and datasets on chat are here hf tk: https://paperswithcode.com/datasets?q=chat&v=lst&o=newest")
|
| 141 |
+
|
| 142 |
+
with gr.Row():
|
| 143 |
+
t1 = gr.Textbox(lines=1, default="", label="Chat Text:")
|
| 144 |
+
b1 = gr.Button("Send Message")
|
| 145 |
|
| 146 |
+
with gr.Row(): # inputs and buttons
|
| 147 |
+
s1 = gr.State([])
|
| 148 |
+
s2 = gr.Markdown()
|
| 149 |
+
with gr.Row():
|
| 150 |
+
df1 = gr.Dataframe(wrap=True, max_rows=1000, overflow_row_behaviour= "paginate")
|
| 151 |
+
#chatoutput = gr.Dataframe(wrap=True, max_rows=1000, overflow_row_behaviour= "paginate", datatype = ["markdown", "markdown"], headers=['url', 'prompt'])
|
| 152 |
+
|
| 153 |
+
b1.click(fn=chat, inputs=[t1, s1], outputs=[s1, df1])
|
| 154 |
+
|
| 155 |
+
demo.launch(debug=True, show_error=True)
|
|
|
|
|
|