vitaliy-sharandin commited on
Commit
b0cc410
1 Parent(s): 6035fd2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -7
app.py CHANGED
@@ -1,6 +1,3 @@
1
- import gradio as gr
2
- from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
3
-
4
  model = AutoModelForCausalLM.from_pretrained(
5
  'vitaliy-sharandin/wiseai',
6
  load_in_8bit=True,
@@ -10,9 +7,28 @@ tokenizer = AutoTokenizer.from_pretrained('vitaliy-sharandin/wiseai')
10
 
11
  pipe = pipeline('text-generation', model=model,tokenizer=tokenizer)
12
 
13
- def generate_text(prompt):
14
- result = pipe(prompt, max_length=200, do_sample=True, temperature=0.9, num_return_sequences=1, return_full_text=False)
15
- return result[0]['generated_text']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- iface = gr.Interface(fn=generate_text, inputs="text", outputs="text")
 
 
18
  iface.launch()
 
 
 
 
1
  model = AutoModelForCausalLM.from_pretrained(
2
  'vitaliy-sharandin/wiseai',
3
  load_in_8bit=True,
 
7
 
8
  pipe = pipeline('text-generation', model=model,tokenizer=tokenizer)
9
 
10
+ def generate_text(instruction, input):
11
+ if not instruction.strip():
12
+ return str('The instruction field is required.')
13
+
14
+ if instruction.strip() and input.strip():
15
+ input_prompt = (f"Below is an instruction that describes a task. "
16
+ "Write a response that appropriately completes the request.\n\n"
17
+ "### Instruction:\n"
18
+ f"{instruction}\n\n"
19
+ "### Input:\n"
20
+ f"{input}\n\n"
21
+ f"### Response: \n")
22
+ else :
23
+ input_prompt = (f"Below is an instruction that describes a task. "
24
+ "Write a response that appropriately completes the request.\n\n"
25
+ "### Instruction:\n"
26
+ f"{instruction}\n\n"
27
+ f"### Response: \n")
28
+ result = pipe(input_prompt, max_length=200, top_p=0.9, temperature=0.9, num_return_sequences=1, return_full_text=False)[0]['generated_text']
29
+ return result[:str(result).find("###")]
30
 
31
+ iface = gr.Interface(fn=generate_text, inputs=[gr.Textbox(label="Instruction"),
32
+ gr.Textbox(label="Additional Input")],
33
+ outputs=gr.Textbox(label="Response"))
34
  iface.launch()