Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,27 +15,16 @@ os.environ["OPENAI_API_KEY"] = os.environ['SECRET_CODE']
|
|
| 15 |
DATASET_REPO_URL = "https://huggingface.co/datasets/peterpull/MediatorBot"
|
| 16 |
DATA_FILENAME = "data.csv"
|
| 17 |
DATA_FILE = os.path.join("data", DATA_FILENAME)
|
|
|
|
|
|
|
| 18 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 19 |
print("HF TOKEN is none?", HF_TOKEN is None)
|
| 20 |
print("HF hub ver", huggingface_hub.__version__)
|
| 21 |
|
| 22 |
-
# overriding/appending to the gradio template
|
| 23 |
-
SCRIPT = """
|
| 24 |
-
<script>
|
| 25 |
-
if (!window.hasBeenRun) {
|
| 26 |
-
window.hasBeenRun = true;
|
| 27 |
-
console.log("should only happen once");
|
| 28 |
-
document.querySelector("button.submit").click();
|
| 29 |
-
}
|
| 30 |
-
</script>
|
| 31 |
-
"""
|
| 32 |
-
with open(os.path.join(gr.networking.STATIC_TEMPLATE_LIB, "frontend", "index.html"), "a") as f:
|
| 33 |
-
f.write(SCRIPT)
|
| 34 |
-
|
| 35 |
-
|
| 36 |
repo = Repository(
|
| 37 |
-
local_dir="data",
|
| 38 |
-
|
|
|
|
| 39 |
|
| 40 |
def generate_html() -> str:
|
| 41 |
with open(DATA_FILE) as csvfile:
|
|
@@ -56,12 +45,12 @@ def generate_html() -> str:
|
|
| 56 |
html += "</div>"
|
| 57 |
return html
|
| 58 |
|
| 59 |
-
def store_message(
|
| 60 |
if name and message:
|
| 61 |
with open(DATA_FILE, "a") as csvfile:
|
| 62 |
writer = csv.DictWriter(csvfile, fieldnames=["User", "Chatbot", "time"])
|
| 63 |
writer.writerow(
|
| 64 |
-
{"User":
|
| 65 |
)
|
| 66 |
commit_url = repo.push_to_hub()
|
| 67 |
print(commit_url)
|
|
@@ -82,6 +71,8 @@ def chatbot(input_text, mentioned_person='Mediator John Haynes'):
|
|
| 82 |
index = get_index('./index/indexsmall.json')
|
| 83 |
prompt = f"You are {mentioned_person}: {input_text}\n\n At the end of your answer ask a provocative question."
|
| 84 |
response = index.query(prompt, response_mode="compact")
|
|
|
|
|
|
|
| 85 |
|
| 86 |
# return the response
|
| 87 |
return response.response
|
|
|
|
| 15 |
DATASET_REPO_URL = "https://huggingface.co/datasets/peterpull/MediatorBot"
|
| 16 |
DATA_FILENAME = "data.csv"
|
| 17 |
DATA_FILE = os.path.join("data", DATA_FILENAME)
|
| 18 |
+
|
| 19 |
+
# I am guessing we need a write access token.
|
| 20 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 21 |
print("HF TOKEN is none?", HF_TOKEN is None)
|
| 22 |
print("HF hub ver", huggingface_hub.__version__)
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
repo = Repository(
|
| 25 |
+
local_dir="data",
|
| 26 |
+
clone_from=DATASET_REPO_URL,
|
| 27 |
+
use_auth_token=HF_TOKEN)
|
| 28 |
|
| 29 |
def generate_html() -> str:
|
| 30 |
with open(DATA_FILE) as csvfile:
|
|
|
|
| 45 |
html += "</div>"
|
| 46 |
return html
|
| 47 |
|
| 48 |
+
def store_message(chatinput: str, chatresponse: str):
|
| 49 |
if name and message:
|
| 50 |
with open(DATA_FILE, "a") as csvfile:
|
| 51 |
writer = csv.DictWriter(csvfile, fieldnames=["User", "Chatbot", "time"])
|
| 52 |
writer.writerow(
|
| 53 |
+
{"User": chatinput, "Chatbot": chatresponse, "time": str(datetime.now())}
|
| 54 |
)
|
| 55 |
commit_url = repo.push_to_hub()
|
| 56 |
print(commit_url)
|
|
|
|
| 71 |
index = get_index('./index/indexsmall.json')
|
| 72 |
prompt = f"You are {mentioned_person}: {input_text}\n\n At the end of your answer ask a provocative question."
|
| 73 |
response = index.query(prompt, response_mode="compact")
|
| 74 |
+
|
| 75 |
+
store_message(input_text,response)
|
| 76 |
|
| 77 |
# return the response
|
| 78 |
return response.response
|