RishuD7 commited on
Commit
2f89ce3
1 Parent(s): f9f19e1

First commit and deploy

Browse files
Files changed (2) hide show
  1. app.py +55 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import transformers
2
+ import torch
3
+ import gc
4
+ from transformers import AutoTokenizer, AutoModelForCausalLM
5
+ import gradio as gr
6
+
7
+
8
+ # Load the model
9
+ model = "tiiuae/falcon-7b-instruct"
10
+ instruction = "Draft an apology email to a customer who experienced a delay in their order and provide reassurance that the issue has been resolved"
11
+
12
+
13
+ tokenizer = AutoTokenizer.from_pretrained(model)
14
+ pipeline = transformers.pipeline(
15
+ "text-generation",
16
+ model=model,
17
+ tokenizer=tokenizer,
18
+ torch_dtype=torch.bfloat16,
19
+ trust_remote_code=True,
20
+ device_map="auto",
21
+ )
22
+
23
+ def predict(instruction: str):
24
+ """
25
+ The `predict` function takes an instruction as input and uses a pre-trained language model to
26
+ generate a predicted sequence of text based on the instruction.
27
+
28
+ :param instruction: The instruction parameter is a string that represents the input for which you
29
+ want to generate a prediction. It could be a question, a prompt, or any other kind of input that you
30
+ want the model to generate a response for
31
+ :type instruction: str
32
+ :return: The function `predict` returns a string that represents the generated text from the model.
33
+ """
34
+ sequences = pipeline(
35
+ instruction,
36
+ max_length=500,
37
+ do_sample=True,
38
+ top_k=10,
39
+ num_return_sequences=1,
40
+ eos_token_id=tokenizer.eos_token_id,
41
+ )
42
+ for seq in sequences:
43
+ result = f"Result: {seq['generated_text']}"
44
+ gc.collect()
45
+ torch.cuda.empty_cache()
46
+ return result
47
+
48
+ gr.Interface(
49
+ predict,
50
+ inputs=[
51
+ gr.inputs.Textbox(lines=2, default=instruction, label="Instruction"),
52
+ ],
53
+ outputs=[gr.outputs.Textbox(label="Output")],
54
+ title= "XGen"
55
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ transformers
2
+ einops
3
+ accelerate
4
+ xformers
5
+ gradio