Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,10 +2,13 @@ from gpt_index import GPTSimpleVectorIndex
|
|
| 2 |
from langchain import OpenAI
|
| 3 |
import gradio as gr
|
| 4 |
from gradio import Interface, Textbox
|
|
|
|
| 5 |
import os
|
| 6 |
import datetime
|
| 7 |
-
|
| 8 |
-
from huggingface_hub import
|
|
|
|
|
|
|
| 9 |
|
| 10 |
os.environ["OPENAI_API_KEY"] = os.environ['SECRET_CODE']
|
| 11 |
|
|
@@ -19,15 +22,19 @@ INDEX_FILE = os.path.join("data", INDEX_FILENAME)
|
|
| 19 |
# 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 |
|
| 23 |
-
#
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
def generate_text() -> str:
|
| 30 |
-
with open(
|
| 31 |
text = ""
|
| 32 |
for line in file:
|
| 33 |
row_parts = line.strip().split(",")
|
|
@@ -40,21 +47,24 @@ def generate_text() -> str:
|
|
| 40 |
|
| 41 |
def store_message(chatinput: str, chatresponse: str):
|
| 42 |
if chatinput and chatresponse:
|
| 43 |
-
with open(
|
| 44 |
-
file.write(f"{datetime.
|
| 45 |
-
print(f"Wrote to datafile: {datetime.
|
| 46 |
-
|
| 47 |
-
#
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
return generate_text()
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
# gets the index file which is the context data
|
| 58 |
def get_index(index_file_path):
|
| 59 |
if os.path.exists(index_file_path):
|
| 60 |
index_size = os.path.getsize(index_file_path)
|
|
@@ -82,7 +92,7 @@ with open('about.txt', 'r') as file:
|
|
| 82 |
|
| 83 |
iface = Interface(
|
| 84 |
fn=chatbot,
|
| 85 |
-
inputs=Textbox("
|
| 86 |
outputs="text",
|
| 87 |
title="AI Chatbot trained on J. Haynes mediation material, v0.5",
|
| 88 |
description=about)
|
|
|
|
| 2 |
from langchain import OpenAI
|
| 3 |
import gradio as gr
|
| 4 |
from gradio import Interface, Textbox
|
| 5 |
+
import sys
|
| 6 |
import os
|
| 7 |
import datetime
|
| 8 |
+
import huggingface_hub
|
| 9 |
+
from huggingface_hub import Repository
|
| 10 |
+
from datetime import datetime
|
| 11 |
+
import csv
|
| 12 |
|
| 13 |
os.environ["OPENAI_API_KEY"] = os.environ['SECRET_CODE']
|
| 14 |
|
|
|
|
| 22 |
# we need a write access token.
|
| 23 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 24 |
print("HF TOKEN is none?", HF_TOKEN is None)
|
| 25 |
+
print("HF hub ver", huggingface_hub.__version__)
|
| 26 |
|
| 27 |
+
#Clones the distant repo to the local repo
|
| 28 |
+
repo = Repository(
|
| 29 |
+
local_dir='data',
|
| 30 |
+
clone_from=DATASET_REPO_URL,
|
| 31 |
+
use_auth_token=HF_TOKEN)
|
| 32 |
+
|
| 33 |
+
print(f"Repo local_dir: {repo.local_dir}")
|
| 34 |
+
print(f"Repo files: {os.listdir(repo.local_dir)}")
|
| 35 |
|
| 36 |
def generate_text() -> str:
|
| 37 |
+
with open(DATA_FILE) as file:
|
| 38 |
text = ""
|
| 39 |
for line in file:
|
| 40 |
row_parts = line.strip().split(",")
|
|
|
|
| 47 |
|
| 48 |
def store_message(chatinput: str, chatresponse: str):
|
| 49 |
if chatinput and chatresponse:
|
| 50 |
+
with open(DATA_FILE, "a") as file:
|
| 51 |
+
file.write(f"{datetime.now()},{chatinput},{chatresponse}\n")
|
| 52 |
+
print(f"Wrote to datafile: {datetime.now()},{chatinput},{chatresponse}\n")
|
| 53 |
+
|
| 54 |
+
# Add the updated data file to the staged changes
|
| 55 |
+
repo.git_add(DATA_FILENAME)
|
| 56 |
+
|
| 57 |
+
# Commit the changes with a commit message
|
| 58 |
+
commit_message = "Added new data"
|
| 59 |
+
repo.git_commit(commit_message)
|
| 60 |
+
|
| 61 |
+
# Push the changes to the remote repository
|
| 62 |
+
repo.push(remote_name='origin', branch_name='main', use_auth_token=HF_TOKEN)
|
| 63 |
|
| 64 |
return generate_text()
|
| 65 |
|
| 66 |
+
|
| 67 |
+
#gets the index file which is the context data
|
|
|
|
| 68 |
def get_index(index_file_path):
|
| 69 |
if os.path.exists(index_file_path):
|
| 70 |
index_size = os.path.getsize(index_file_path)
|
|
|
|
| 92 |
|
| 93 |
iface = Interface(
|
| 94 |
fn=chatbot,
|
| 95 |
+
inputs=Textbox("Type here"),
|
| 96 |
outputs="text",
|
| 97 |
title="AI Chatbot trained on J. Haynes mediation material, v0.5",
|
| 98 |
description=about)
|