Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,51 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import openai
|
| 3 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
user_db = {os.environ["admin_username"]: os.environ["admin_password"],
|
| 6 |
os.environ["username"]: os.environ["password"],
|
|
@@ -17,7 +62,7 @@ def mr_bot(premise, tokens, temperature):
|
|
| 17 |
)
|
| 18 |
return response['choices'][0]["text"]
|
| 19 |
|
| 20 |
-
description = "Ask Mr. Bot a question or give him a command."
|
| 21 |
|
| 22 |
demo = gr.Interface(fn=mr_bot,
|
| 23 |
inputs=["text", gr.Slider(1, 800), gr.Slider(0, 1)],
|
|
|
|
| 1 |
import os
|
| 2 |
+
import csv
|
| 3 |
import openai
|
| 4 |
import gradio as gr
|
| 5 |
+
import huggingface_hub
|
| 6 |
+
from huggingface_hub import Repository
|
| 7 |
+
|
| 8 |
+
DATASET_REPO_URL = "https://huggingface.co/datasets/jadend/mr_bot_requests"
|
| 9 |
+
DATA_FILENAME = "premise_input.csv"
|
| 10 |
+
DATA_FILE = os.path.join("premise_input", DATA_FILENAME)
|
| 11 |
+
|
| 12 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 13 |
+
print("is none?", HF_TOKEN is None)
|
| 14 |
+
|
| 15 |
+
repo = Repository(
|
| 16 |
+
local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def generate_html() -> str:
|
| 20 |
+
with open(DATA_FILE) as csvfile:
|
| 21 |
+
reader = csv.DictReader(csvfile)
|
| 22 |
+
rows = []
|
| 23 |
+
for row in reader:
|
| 24 |
+
rows.append(row)
|
| 25 |
+
rows.reverse()
|
| 26 |
+
if len(rows) == 0:
|
| 27 |
+
return "no premises yet"
|
| 28 |
+
else:
|
| 29 |
+
html = "<div class='chatbot'>"
|
| 30 |
+
for row in rows:
|
| 31 |
+
html += "<div>"
|
| 32 |
+
html += f"<span class='premise'>{row['premise']}</span>"
|
| 33 |
+
html += "</div>"
|
| 34 |
+
html += "</div>"
|
| 35 |
+
return html
|
| 36 |
+
|
| 37 |
+
def store_message(premise: str):
|
| 38 |
+
if premise:
|
| 39 |
+
with open(DATA_FILE, "a") as csvfile:
|
| 40 |
+
writer = csv.DictWriter(csvfile, fieldnames=["premise", "time"])
|
| 41 |
+
writer.writerow(
|
| 42 |
+
{"premise": premise, "time": str(datetime.now())}
|
| 43 |
+
)
|
| 44 |
+
commit_url = repo.push_to_hub()
|
| 45 |
+
print(commit_url)
|
| 46 |
+
|
| 47 |
+
return generate_html()
|
| 48 |
+
|
| 49 |
|
| 50 |
user_db = {os.environ["admin_username"]: os.environ["admin_password"],
|
| 51 |
os.environ["username"]: os.environ["password"],
|
|
|
|
| 62 |
)
|
| 63 |
return response['choices'][0]["text"]
|
| 64 |
|
| 65 |
+
description = "Ask Mr. Bot a question or give him a command. Entered Prompts are logged and stored securely."
|
| 66 |
|
| 67 |
demo = gr.Interface(fn=mr_bot,
|
| 68 |
inputs=["text", gr.Slider(1, 800), gr.Slider(0, 1)],
|