Commit
•
84054b0
1
Parent(s):
b015e70
test env var
Browse files
app.py
CHANGED
@@ -1,41 +1,47 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
import os
|
3 |
import torch
|
4 |
import transformers
|
5 |
from transformers import AutoTokenizer
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
# return pipe_flan(input_text)["generated_text"]
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
token=os.environ["HF_TOKEN"],
|
15 |
-
)
|
16 |
-
pipeline = transformers.pipeline(
|
17 |
-
"text-generation",
|
18 |
-
model=model,
|
19 |
-
torch_dtype=torch.float16,
|
20 |
-
device_map="auto",
|
21 |
-
token=os.environ["HF_TOKEN"],
|
22 |
-
low_cpu_mem_usage=False,
|
23 |
-
)
|
24 |
|
25 |
-
|
26 |
-
sequences = pipeline(
|
27 |
-
input_text,
|
28 |
-
do_sample=True,
|
29 |
-
top_k=10,
|
30 |
-
num_return_sequences=1,
|
31 |
-
eos_token_id=tokenizer.eos_token_id,
|
32 |
-
max_length=200,
|
33 |
-
)
|
34 |
-
output_text = ""
|
35 |
-
for seq in sequences:
|
36 |
-
output_text += seq["generated_text"] + "\n"
|
37 |
-
return output_text
|
38 |
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
1 |
import gradio as gr
|
2 |
+
import logging
|
3 |
import os
|
4 |
import torch
|
5 |
import transformers
|
6 |
from transformers import AutoTokenizer
|
7 |
|
8 |
+
print(os.environ["HF_TOKEN"][:5])
|
9 |
+
logging.info(os.environ["HF_TOKEN"][:5])
|
|
|
10 |
|
11 |
+
pipe_flan = transformers.pipeline("text2text-generation", model="google/flan-t5-small")
|
12 |
+
def google_flan(input_text):
|
13 |
+
return pipe_flan(input_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
demo = gr.Interface(fn=google_flan, inputs="text", outputs="text")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
# model = "meta-llama/Llama-2-7b-chat-hf"
|
18 |
+
# tokenizer = AutoTokenizer.from_pretrained(
|
19 |
+
# model,
|
20 |
+
# token=os.environ["HF_TOKEN"],
|
21 |
+
# )
|
22 |
+
# pipeline = transformers.pipeline(
|
23 |
+
# "text-generation",
|
24 |
+
# model=model,
|
25 |
+
# torch_dtype=torch.float16,
|
26 |
+
# device_map="auto",
|
27 |
+
# token=os.environ["HF_TOKEN"],
|
28 |
+
# low_cpu_mem_usage=True,
|
29 |
+
# )
|
30 |
+
|
31 |
+
# def llama2(input_text):
|
32 |
+
# sequences = pipeline(
|
33 |
+
# input_text,
|
34 |
+
# do_sample=True,
|
35 |
+
# top_k=10,
|
36 |
+
# num_return_sequences=1,
|
37 |
+
# eos_token_id=tokenizer.eos_token_id,
|
38 |
+
# max_length=200,
|
39 |
+
# )
|
40 |
+
# output_text = ""
|
41 |
+
# for seq in sequences:
|
42 |
+
# output_text += seq["generated_text"] + "\n"
|
43 |
+
# return output_text
|
44 |
+
|
45 |
+
# demo = gr.Interface(fn=llama2, inputs="text", outputs="text")
|
46 |
|
47 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|