Spaces:
Runtime error
Runtime error
Commit
·
1809cb2
1
Parent(s):
3d2a0ba
changing to gradio interface
Browse files
app.py
CHANGED
|
@@ -1,39 +1,34 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
# return sequences[0]['generated_text']
|
| 37 |
-
|
| 38 |
-
# iface = gr.Interface(fn=falcon, inputs="text", outputs="text")
|
| 39 |
-
# iface.launch() # To create a public link, set `share=True`
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 4 |
+
import transformers
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def falcon(input_text):
|
| 9 |
+
model = "tiiuae/falcon-40b"
|
| 10 |
+
|
| 11 |
+
tokenizer = AutoTokenizer.from_pretrained(model)
|
| 12 |
+
pipeline = transformers.pipeline(
|
| 13 |
+
"text-generation",
|
| 14 |
+
model=model,
|
| 15 |
+
tokenizer=tokenizer,
|
| 16 |
+
torch_dtype=torch.bfloat16,
|
| 17 |
+
trust_remote_code=True,
|
| 18 |
+
device_map="auto",
|
| 19 |
+
)
|
| 20 |
+
sequences = pipeline(
|
| 21 |
+
input_text, # "Was ist das höchste Gebäude in der Welt?"
|
| 22 |
+
max_length=200,
|
| 23 |
+
do_sample=True,
|
| 24 |
+
top_k=10,
|
| 25 |
+
num_return_sequences=1,
|
| 26 |
+
eos_token_id=tokenizer.eos_token_id,
|
| 27 |
+
)
|
| 28 |
+
for seq in sequences:
|
| 29 |
+
print(f"Result: {seq['generated_text']}")
|
| 30 |
+
|
| 31 |
+
return sequences[0]['generated_text']
|
| 32 |
+
|
| 33 |
+
iface = gr.Interface(fn=falcon, inputs="text", outputs="text")
|
| 34 |
+
iface.launch() # To create a public link, set `share=True`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|