PhantHive commited on
Commit
41041ff
1 Parent(s): 967e6d2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/llama-2-7b-momo")
9
+ model = AutoModelForCausalLM.from_pretrained("NousResearch/Llama-2-7b-chat-hf")
10
+ model = PeftModel.from_pretrained(model, "PhantHive/llama-2-7b-momo")
11
+
12
+ # Load the tokenizer
13
+ tokenizer = AutoTokenizer.from_pretrained("NousResearch/Llama-2-7b-chat-hf")
14
+
15
+ def greet(text):
16
+ batch = tokenizer(f"'{text}' ->: ", return_tensors='pt')
17
+
18
+ with torch.cuda.amp.autocast():
19
+ output_tokens = model.generate(**batch, max_new_tokens=100)
20
+
21
+ return tokenizer.decode(output_tokens[0], skip_special_tokens=True)
22
+
23
+
24
+ iface = gr.Interface(fn=greet, inputs="text", outputs="text")
25
+ iface.launch()