Spaces:
Sleeping
Sleeping
Upload 2 files
#1
by
awinml
- opened
- app.py +43 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
import transformers
|
4 |
+
import torch
|
5 |
+
|
6 |
+
model = AutoModelForCausalLM.from_pretrained(
|
7 |
+
"tiiuae/falcon-7b-instruct",
|
8 |
+
torch_dtype=torch.bfloat16,
|
9 |
+
trust_remote_code=True,
|
10 |
+
device_map="auto",
|
11 |
+
low_cpu_mem_usage=True,
|
12 |
+
offload_folder="/",
|
13 |
+
)
|
14 |
+
tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-7b-instruct")
|
15 |
+
|
16 |
+
|
17 |
+
def create_embedding(input_text):
|
18 |
+
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
19 |
+
attention_mask = torch.ones(input_ids.shape)
|
20 |
+
|
21 |
+
output = model.generate(
|
22 |
+
input_ids,
|
23 |
+
attention_mask=attention_mask,
|
24 |
+
max_length=200,
|
25 |
+
do_sample=True,
|
26 |
+
top_k=10,
|
27 |
+
num_return_sequences=1,
|
28 |
+
eos_token_id=tokenizer.eos_token_id,
|
29 |
+
)
|
30 |
+
|
31 |
+
output_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
32 |
+
print(output_text)
|
33 |
+
return output_text
|
34 |
+
|
35 |
+
|
36 |
+
instructor_model_embeddings = gr.Interface(
|
37 |
+
fn=create_embedding,
|
38 |
+
inputs=[
|
39 |
+
gr.inputs.Textbox(label="Input Text"),
|
40 |
+
],
|
41 |
+
outputs=gr.inputs.Textbox(label="Generated Text"),
|
42 |
+
title="Falcon-7B Instruct",
|
43 |
+
).launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
datasets
|
2 |
+
transformers
|
3 |
+
accelerate
|
4 |
+
einops
|
5 |
+
safetensors
|