Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +10 -8
- requirements.txt +2 -0
app.py
CHANGED
|
@@ -17,17 +17,17 @@ import wikipediaapi
|
|
| 17 |
wiki_wiki = wikipediaapi.Wikipedia('Organika (cmatthewbrown@gmail.com)', 'en')
|
| 18 |
|
| 19 |
## ctransformers disabled for now
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
|
| 27 |
# Use a pipeline as a high-level helper
|
| 28 |
from transformers import pipeline
|
| 29 |
topic_model = pipeline("zero-shot-classification", model="valhalla/distilbart-mnli-12-9")
|
| 30 |
-
model = pipeline("text-generation", model="Colby/StarCoder-3B-WoW-JSON", device=0)
|
| 31 |
|
| 32 |
def merlin_chat(message, history):
|
| 33 |
chat_text = ""
|
|
@@ -78,11 +78,13 @@ def merlin_chat(message, history):
|
|
| 78 |
user_msg = {'role': 'user', 'content': message}
|
| 79 |
prompt = "[" + json.dumps(system_msg) + chat_json + json.dumps(user_msg) + "{'role': 'assistant, 'content': '*recalls \""
|
| 80 |
for attempt in range(3):
|
| 81 |
-
result = model(prompt, max_new_tokens=250, return_full_text=False, handle_long_generation="hole")
|
|
|
|
| 82 |
response = result[0]['generated_text']
|
| 83 |
start = 0
|
| 84 |
end = 0
|
| 85 |
cleanStr = response.lstrip()
|
|
|
|
| 86 |
start = cleanStr.find('{') # this should skip over whatever it recalls to what it says next
|
| 87 |
if start<=0:
|
| 88 |
continue
|
|
|
|
| 17 |
wiki_wiki = wikipediaapi.Wikipedia('Organika (cmatthewbrown@gmail.com)', 'en')
|
| 18 |
|
| 19 |
## ctransformers disabled for now
|
| 20 |
+
from ctransformers import AutoModelForCausalLM
|
| 21 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 22 |
+
"Colby/StarCoder-3B-WoW-JSON",
|
| 23 |
+
model_file="StarCoder-3B-WoW-JSON-ggml.bin",
|
| 24 |
+
model_type="gpt_bigcode"
|
| 25 |
+
)
|
| 26 |
|
| 27 |
# Use a pipeline as a high-level helper
|
| 28 |
from transformers import pipeline
|
| 29 |
topic_model = pipeline("zero-shot-classification", model="valhalla/distilbart-mnli-12-9")
|
| 30 |
+
#model = pipeline("text-generation", model="Colby/StarCoder-3B-WoW-JSON", device=0)
|
| 31 |
|
| 32 |
def merlin_chat(message, history):
|
| 33 |
chat_text = ""
|
|
|
|
| 78 |
user_msg = {'role': 'user', 'content': message}
|
| 79 |
prompt = "[" + json.dumps(system_msg) + chat_json + json.dumps(user_msg) + "{'role': 'assistant, 'content': '*recalls \""
|
| 80 |
for attempt in range(3):
|
| 81 |
+
# result = model(prompt, max_new_tokens=250, return_full_text=False, handle_long_generation="hole")
|
| 82 |
+
result = model(prompt, stop=["]"])
|
| 83 |
response = result[0]['generated_text']
|
| 84 |
start = 0
|
| 85 |
end = 0
|
| 86 |
cleanStr = response.lstrip()
|
| 87 |
+
cleanStr = cleanStr.replace(prompt,"")
|
| 88 |
start = cleanStr.find('{') # this should skip over whatever it recalls to what it says next
|
| 89 |
if start<=0:
|
| 90 |
continue
|
requirements.txt
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
|
|
| 1 |
transformers
|
| 2 |
torch
|
| 3 |
spacy
|
|
|
|
| 4 |
rake_nltk
|
| 5 |
wikipedia-api
|
|
|
|
| 1 |
+
ctransformers
|
| 2 |
transformers
|
| 3 |
torch
|
| 4 |
spacy
|
| 5 |
+
nltk
|
| 6 |
rake_nltk
|
| 7 |
wikipedia-api
|