Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
| 3 |
-
from peft import PeftModel, PeftConfig
|
| 4 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 5 |
-
import torch
|
| 6 |
|
| 7 |
-
|
| 8 |
-
config = PeftConfig.from_pretrained("PhantHive/bigbrain")
|
| 9 |
-
model = AutoModelForCausalLM.from_pretrained("NousResearch/Llama-2-7b-chat-hf")
|
| 10 |
-
model = PeftModel.from_pretrained(model, "PhantHive/bigbrain")
|
| 11 |
-
|
| 12 |
-
# Load the tokenizer
|
| 13 |
-
tokenizer = AutoTokenizer.from_pretrained("NousResearch/Llama-2-7b-chat-hf")
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
def greet(text):
|
| 17 |
-
batch = tokenizer(f"'{text}' ->: ", return_tensors='pt')
|
| 18 |
-
|
| 19 |
-
# Use torch.no_grad to disable gradient calculation
|
| 20 |
-
with torch.no_grad():
|
| 21 |
-
output_tokens = model.generate(**batch, do_sample=True, max_new_tokens=50)
|
| 22 |
-
|
| 23 |
-
return tokenizer.decode(output_tokens[0], skip_special_tokens=True)
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 27 |
-
iface.launch()
|
|
|
|
| 1 |
+
# Use a pipeline as a high-level helper
|
| 2 |
+
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
pipe = pipeline("text-generation", model="PhantHive/bigbrain")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|