arshad615 commited on
Commit
78749bb
·
1 Parent(s): ee2f65b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -33
app.py CHANGED
@@ -1,37 +1,41 @@
1
- # from transformers import AutoTokenizer, AutoModelForCausalLM
2
- # import transformers
3
- # import torch
4
- # import gradio as gr
5
 
6
- # model = "tiiuae/falcon-7b-instruct"
7
 
8
- # tokenizer = AutoTokenizer.from_pretrained(model)
9
- # pipeline = transformers.pipeline(
10
- # "text-generation",
11
- # model=model,
12
- # tokenizer=tokenizer,
13
- # torch_dtype=torch.bfloat16,
14
- # trust_remote_code=True,
15
- # device_map="auto",
16
- # )
17
- # sequences = pipeline(
18
- # "Girafatron is obsessed with giraffes, the most glorious animal on the face of this Earth. Giraftron believes all other animals are irrelevant when compared to the glorious majesty of the giraffe.\nDaniel: Hello, Girafatron!\nGirafatron:",
19
- # max_length=200,
20
- # do_sample=True,
21
- # top_k=10,
22
- # num_return_sequences=1,
23
- # eos_token_id=tokenizer.eos_token_id,
24
- # )
25
- # def predict(image):
26
- # predictions = pipeline(image)
27
- # return {seq['generated_text'] for seq in sequences}
28
 
29
- # gr.Interface(
30
- # predict,
31
- # inputs=gr.inputs.Image(label="Ask Enything", type="filepath"),
32
- # outputs=gr.outputs.Label(num_top_classes=2),
33
- # title="Hot Dog? Or Not?",
34
- # ).launch()
35
- import gradio as gr
 
36
 
37
- gr.load("models/tiiuae/falcon-7b-instruct").launch()
 
 
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelForCausalLM
2
+ import transformers
3
+ import torch
4
+ import gradio as gr
5
 
6
+ model = "tiiuae/falcon-7b-instruct"
7
 
8
+ tokenizer = AutoTokenizer.from_pretrained(model)
9
+ pipeline = transformers.pipeline(
10
+ "text-generation",
11
+ model=model,
12
+ tokenizer=tokenizer,
13
+ torch_dtype=torch.bfloat16,
14
+ trust_remote_code=True,
15
+ device_map="auto",
16
+ )
17
+ def generate_text(input_text):
18
+ sequences = pipeline(
19
+ "Girafatron is obsessed with giraffes, the most glorious animal on the face of this Earth. Giraftron believes all other animals are irrelevant when compared to the glorious majesty of the giraffe.\nDaniel: Hello, Girafatron!\nGirafatron:",
20
+ max_length=200,
21
+ do_sample=True,
22
+ top_k=10,
23
+ num_return_sequences=1,
24
+ eos_token_id=tokenizer.eos_token_id,
25
+ )
26
+ return sequences;
 
27
 
28
+
29
+ gr.Interface(
30
+ generate_text,
31
+ inputs="text",
32
+ outputs="text",
33
+ title="Text Generation App",
34
+ description="Generate text based on input.",
35
+ ).launch()
36
 
37
+ # def generate_text(input_text):
38
+ # input_ids = tokenizer.encode(input_text, return_tensors="pt")
39
+ # output = model.generate(input_ids, max_length=50, num_return_sequences=1)
40
+ # generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
41
+ # return generated_text