Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,34 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
from transformers import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import transformers
|
| 5 |
import torch
|
| 6 |
|
| 7 |
-
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
tokenizer=tokenizer,
|
| 14 |
-
torch_dtype=torch.bfloat16,
|
| 15 |
trust_remote_code=True,
|
| 16 |
-
|
| 17 |
device_map="auto",
|
| 18 |
)
|
|
|
|
| 19 |
|
| 20 |
-
def falcon(input_text):
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
eos_token_id=tokenizer.eos_token_id,
|
| 29 |
-
)
|
| 30 |
-
for seq in sequences:
|
| 31 |
-
print(f"Result: {seq['generated_text']}")
|
| 32 |
|
| 33 |
-
return sequences[0]['generated_text']
|
| 34 |
|
| 35 |
iface = gr.Interface(fn=falcon, inputs="text", outputs="text")
|
| 36 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
from transformers import (
|
| 4 |
+
AutoModelForCausalLM,
|
| 5 |
+
AutoConfig,
|
| 6 |
+
AutoTokenizer,
|
| 7 |
+
BitsAndBytesConfig,
|
| 8 |
+
)
|
| 9 |
import transformers
|
| 10 |
import torch
|
| 11 |
|
| 12 |
+
model_name = "tiiuae/falcon-40b"
|
| 13 |
|
| 14 |
+
config = AutoConfig.from_pretrained(model_name, trust_remote_code=True)
|
| 15 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 16 |
+
model,
|
| 17 |
+
quantization_config=BitsAndBytesConfig(load_in_4bit=True),
|
|
|
|
|
|
|
| 18 |
trust_remote_code=True,
|
| 19 |
+
torch_dtype=torch.bfloat16,
|
| 20 |
device_map="auto",
|
| 21 |
)
|
| 22 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 23 |
|
|
|
|
| 24 |
|
| 25 |
+
def falcon(input_text):
|
| 26 |
+
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to("cuda")
|
| 27 |
+
outputs = model.generate(input_ids, max_length=100, do_sample=True, top_k=10)
|
| 28 |
+
decoded = tokenizer.decode(outputs[0])
|
| 29 |
+
|
| 30 |
+
return decoded
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
|
|
|
| 32 |
|
| 33 |
iface = gr.Interface(fn=falcon, inputs="text", outputs="text")
|
| 34 |
+
iface.launch() # To create a public link, set `share=True`
|