PhantHive commited on
Commit
2c028a9
·
1 Parent(s): 91614f8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import peft
3
+ from peft import PeftModel, PeftConfig
4
+ from transformers import AutoModelForCausalLM, AutoTokenizer
5
+ import torch
6
+
7
+ # Load the model and config when the script starts
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()