awacke1 commited on
Commit
117b6a7
·
1 Parent(s): 5455896

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -40,11 +40,11 @@ if UseMemory:
40
  local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
41
  )
42
 
43
- def get_df(name: str):
44
  dataset = load_dataset(str, split="train")
45
  return dataset
46
 
47
- def store_message(name: str, message: str):
48
  if name and message:
49
  with open(DATA_FILE, "a") as csvfile:
50
  writer = csv.DictWriter(csvfile, fieldnames=[ "time", "message", "name", ])
@@ -59,14 +59,14 @@ def store_message(name: str, message: str):
59
 
60
  # f=get_df(DATASET_REPO_ID)
61
  # print(f)
62
- return ""
63
  # ----------------------------------------------- For Memory
64
 
65
  mname = "facebook/blenderbot-400M-distill"
66
  model = BlenderbotForConditionalGeneration.from_pretrained(mname)
67
  tokenizer = BlenderbotTokenizer.from_pretrained(mname)
68
 
69
- def take_last_tokens(inputs, note_history, history):
70
  """Filter the last 128 tokens"""
71
  if inputs['input_ids'].shape[1] > 128:
72
  inputs['input_ids'] = torch.tensor([inputs['input_ids'][0][-128:].tolist()])
@@ -75,7 +75,7 @@ def take_last_tokens(inputs, note_history, history):
75
  history = history[1:]
76
  return inputs, note_history, history
77
 
78
- def add_note_to_history(note, note_history):
79
  """Add a note to the historical information"""
80
  note_history.append(note)
81
  note_history = '</s> <s>'.join(note_history)
@@ -85,7 +85,7 @@ title = "💬ChatBack🧠💾"
85
  description = """Chatbot With persistent memory dataset allowing multiagent system AI to access a shared dataset as memory pool with stored interactions.
86
  Current Best SOTA Chatbot: https://huggingface.co/facebook/blenderbot-400M-distill?text=Hey+my+name+is+ChatBack%21+Are+you+ready+to+rock%3F """
87
 
88
- def chat(message, history):
89
  history = history or []
90
  if history:
91
  history_useful = ['</s> <s>'.join([str(a[0])+'</s> <s>'+str(a[1]) for a in history])]
@@ -101,6 +101,11 @@ def chat(message, history):
101
  history.append((list_history[-2], list_history[-1]))
102
  ret = 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.
103
  return history, history
 
 
 
 
 
104
 
105
  gr.Interface(
106
  fn=chat,
 
40
  local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
41
  )
42
 
43
+ async def get_df(name: str):
44
  dataset = load_dataset(str, split="train")
45
  return dataset
46
 
47
+ async def store_message(name: str, message: str):
48
  if name and message:
49
  with open(DATA_FILE, "a") as csvfile:
50
  writer = csv.DictWriter(csvfile, fieldnames=[ "time", "message", "name", ])
 
59
 
60
  # f=get_df(DATASET_REPO_ID)
61
  # print(f)
62
+ return commit_url
63
  # ----------------------------------------------- For Memory
64
 
65
  mname = "facebook/blenderbot-400M-distill"
66
  model = BlenderbotForConditionalGeneration.from_pretrained(mname)
67
  tokenizer = BlenderbotTokenizer.from_pretrained(mname)
68
 
69
+ async def take_last_tokens(inputs, note_history, history):
70
  """Filter the last 128 tokens"""
71
  if inputs['input_ids'].shape[1] > 128:
72
  inputs['input_ids'] = torch.tensor([inputs['input_ids'][0][-128:].tolist()])
 
75
  history = history[1:]
76
  return inputs, note_history, history
77
 
78
+ async def add_note_to_history(note, note_history):
79
  """Add a note to the historical information"""
80
  note_history.append(note)
81
  note_history = '</s> <s>'.join(note_history)
 
85
  description = """Chatbot With persistent memory dataset allowing multiagent system AI to access a shared dataset as memory pool with stored interactions.
86
  Current Best SOTA Chatbot: https://huggingface.co/facebook/blenderbot-400M-distill?text=Hey+my+name+is+ChatBack%21+Are+you+ready+to+rock%3F """
87
 
88
+ async def chat(message, history):
89
  history = history or []
90
  if history:
91
  history_useful = ['</s> <s>'.join([str(a[0])+'</s> <s>'+str(a[1]) for a in history])]
 
101
  history.append((list_history[-2], list_history[-1]))
102
  ret = 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.
103
  return history, history
104
+
105
+ #with gr.Blocks() as demo:
106
+ # gr.Markdown("<h1><center>🥫Datasets🎨</center></h1>")
107
+ # gr.Markdown("""<div align="center">Curated Datasets: <a href = "https://www.kaggle.com/datasets">Kaggle</a>. <a href="https://www.nlm.nih.gov/research/umls/index.html">NLM UMLS</a>. <a href="https://loinc.org/downloads/">LOINC</a>. <a href="https://www.cms.gov/medicare/icd-10/2022-icd-10-cm">ICD10 Diagnosis</a>. <a href="https://icd.who.int/dev11/downloads">ICD11</a>. <a href="https://paperswithcode.com/datasets?q=medical&v=lst&o=newest">Papers,Code,Datasets for SOTA in Medicine</a>. <a href="https://paperswithcode.com/datasets?q=mental&v=lst&o=newest">Mental</a>. <a href="https://paperswithcode.com/datasets?q=behavior&v=lst&o=newest">Behavior</a>. <a href="https://www.cms.gov/medicare-coverage-database/downloads/downloads.aspx">CMS Downloads</a>. <a href="https://www.cms.gov/medicare/fraud-and-abuse/physicianselfreferral/list_of_codes">CMS CPT and HCPCS Procedures and Services</a> """)
108
+
109
 
110
  gr.Interface(
111
  fn=chat,