ToletiSri commited on
Commit
9bc80c6
1 Parent(s): 8a8ccca

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
4
+
5
+ model = AutoModelForCausalLM.from_pretrained("checkpoint",trust_remote_code=True)
6
+ tokenizer = AutoTokenizer.from_pretrained("checkpoint", trust_remote_code=True)
7
+ tokenizer.pad_token = tokenizer.eos_token
8
+
9
+ def inference(prompt, count):
10
+ pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=200)
11
+ result = pipe(f"### Human: {prompt}",max_new_tokens=count)
12
+ out_text = result[0]['generated_text']
13
+ return out_text
14
+
15
+ title = "TSAI S21 Assignment: Adaptive QLoRA training on open assist oasst1 dataset, using microsoft/phi2 model"
16
+ description = "A simple Gradio interface that accepts a context and generates GPT like text "
17
+ examples = [["What is a large language model?","200"],
18
+ ["Explain about monopsony","200"]
19
+ ]
20
+
21
+
22
+ demo = gr.Interface(
23
+ inference,
24
+ inputs = [gr.Textbox(placeholder="Enter a prompt"), gr.Textbox(placeholder="Enter number of characters you want to generate")],
25
+ outputs = [gr.Textbox(label="Chat GPT like text")],
26
+ title = title,
27
+ description = description,
28
+ examples = examples
29
+ )
30
+ demo.launch()