Update app.py
Browse files
app.py
CHANGED
|
@@ -1,48 +1,41 @@
|
|
| 1 |
-
|
| 2 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
-
import torch
|
| 4 |
-
from ctransformers import AutoConfig
|
| 5 |
-
import os
|
| 6 |
|
| 7 |
hf_token = os.environ.get('HF_TOKEN')
|
| 8 |
|
| 9 |
from huggingface_hub import login
|
| 10 |
login(token=hf_token)
|
| 11 |
|
| 12 |
-
config = AutoConfig.from_pretrained( "mistralai/Mistral-7B-Instruct-v0.1")
|
| 13 |
-
config.config.max_new_tokens = 2000
|
| 14 |
-
config.config.context_length = 4000
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
def generate_text(input_text):
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
output
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
max_length=200,
|
| 33 |
-
do_sample=True,
|
| 34 |
-
top_k=10,
|
| 35 |
-
num_return_sequences=1,
|
| 36 |
-
eos_token_id=tokenizer.eos_token_id,
|
| 37 |
-
|
| 38 |
-
)
|
| 39 |
-
|
| 40 |
-
output_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 41 |
-
print(output_text)
|
| 42 |
-
|
| 43 |
-
# Remove Prompt Echo from Generated Text
|
| 44 |
-
cleaned_output_text = output_text.replace(input_text, "")
|
| 45 |
-
return cleaned_output_text
|
| 46 |
|
| 47 |
|
| 48 |
text_generation_interface = gr.Interface(
|
|
|
|
| 1 |
+
from langchain_community.llms.ctransformers import CTransformers
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
hf_token = os.environ.get('HF_TOKEN')
|
| 4 |
|
| 5 |
from huggingface_hub import login
|
| 6 |
login(token=hf_token)
|
| 7 |
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
# config = AutoConfig.from_pretrained("Mistral-7B-v0.1-GGUF")
|
| 10 |
+
# config.config.max_new_tokens = 2000
|
| 11 |
+
# config.config.context_length = 6000
|
| 12 |
+
|
| 13 |
+
# llm = AutoModelForCausalLM.from_pretrained("TheBloke/Mistral-7B-v0.1-GGUF", model_file="mistral-7b-v0.1.Q5_K_M.gguf", model_type="mistral",gpu_layers=0, config=config)
|
| 14 |
+
|
| 15 |
+
MODEL_TYPE = 'mistral'
|
| 16 |
+
MODEL_BIN_PATH = "mistral-7b-instruct-v0.1.Q3_K_S.gguf"
|
| 17 |
+
MAX_NEW_TOKEN = 600
|
| 18 |
+
TEMPRATURE = 0.01
|
| 19 |
+
CONTEXT_LENGTH = 6000
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
llm = CTransformers(
|
| 23 |
+
model=MODEL_BIN_PATH,
|
| 24 |
+
config={
|
| 25 |
+
'max_new_tokens': MAX_NEW_TOKEN,
|
| 26 |
+
'temperature': TEMPRATURE,
|
| 27 |
+
'context_length': CONTEXT_LENGTH
|
| 28 |
+
},
|
| 29 |
+
model_type=MODEL_TYPE
|
| 30 |
+
)
|
| 31 |
|
| 32 |
def generate_text(input_text):
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
output = llm(input_text)
|
| 36 |
+
print(output)
|
| 37 |
+
|
| 38 |
+
return output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
|
| 41 |
text_generation_interface = gr.Interface(
|