dar-tau commited on
Commit
d0d12ff
·
verified ·
1 Parent(s): 03b2400

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import spaces
4
+ from transformers import AutoTokenizer, AutoModel
5
+
6
+
7
+ model_name = "teknium/OpenHermes-2.5-Mistral-7B"
8
+ token = os.environ['hf_token']
9
+
10
+ model = AutoModel.from_pretrained(model_name).cuda()
11
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
12
+
13
+
14
+ system_prompt = '''You are given an input text for a chat interface. Propose auto-completion to the text. You have several roles:
15
+ - Fight under-specification: if the user does not provide sufficient context, propose them a set of relevant suggestions.
16
+ - Complete text: The text provided to you is in the making. If you have a good idea for how to complete - make suggestions.
17
+
18
+ Make sure the suggestions are valid completions of the text! No need for them to complete the text completely.
19
+ Suggest only up to 5 works ahead.
20
+ '''
21
+
22
+ @spaces.GPU
23
+ def generate(text):
24
+ data = [
25
+ {'role': 'system', 'content': system_prompt},
26
+ {'role': 'user', 'content': text}
27
+ ]
28
+ tokenized = tokenizer.apply_chat_template(data, return_tensors='pt')
29
+ return tokenizer.deocode(model.generate(**tokenized).squeeze(0))