Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
from transformers import AutoTokenizer,
|
| 2 |
-
from transformers import pipeline
|
| 3 |
import torch
|
| 4 |
import gradio as gr
|
| 5 |
|
|
@@ -10,8 +9,22 @@ model = AutoModelForSeq2SeqLM.from_pretrained(
|
|
| 10 |
"Kaludi/chatgpt-gpt4-prompts-bart-large-cnn-samsum", from_tf=True)
|
| 11 |
|
| 12 |
# zephyr
|
| 13 |
-
pipe = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-alpha",
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
def useZephyr(prompt):
|
|
@@ -23,12 +36,8 @@ def useZephyr(prompt):
|
|
| 23 |
{"role": "user", "content": prompt},
|
| 24 |
]
|
| 25 |
# https://huggingface.co/docs/transformers/main/en/chat_templating
|
| 26 |
-
|
| 27 |
-
messages, tokenize=False, add_generation_prompt=True)
|
| 28 |
-
print(prompt)
|
| 29 |
|
| 30 |
-
outputs = pipe(prompt, max_new_tokens=256, do_sample=True,
|
| 31 |
-
temperature=0.7, top_k=50, top_p=0.95)
|
| 32 |
return outputs[0]["generated_text"]
|
| 33 |
|
| 34 |
|
|
@@ -57,11 +66,12 @@ def generate_prompt(prompt, max_new_tokens):
|
|
| 57 |
|
| 58 |
|
| 59 |
input_prompt = gr.Textbox(label="Prompt", value="photographer")
|
|
|
|
| 60 |
output_component = gr.Textbox(label="Output")
|
| 61 |
examples = [["photographer"], ["developer"], ["teacher"], [
|
| 62 |
"human resources staff"], ["recipe for ham croquettes"]]
|
| 63 |
description = ""
|
| 64 |
-
PerfectGPT = gr.Interface(useZephyr, inputs=input_prompt, outputs=output_component,
|
| 65 |
examples=examples, title="🗿 PerfectGPT v1 🗿", description=description)
|
| 66 |
|
| 67 |
-
PerfectGPT.launch()
|
|
|
|
| 1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig, pipeline
|
|
|
|
| 2 |
import torch
|
| 3 |
import gradio as gr
|
| 4 |
|
|
|
|
| 9 |
"Kaludi/chatgpt-gpt4-prompts-bart-large-cnn-samsum", from_tf=True)
|
| 10 |
|
| 11 |
# zephyr
|
| 12 |
+
# pipe = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-alpha", torch_dtype=torch.bfloat16, device_map="auto")
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
hf_model_id = "HuggingFaceH4/zephyr-7b-alpha"
|
| 16 |
+
model = AutoModelForCausalLM.from_pretrained(hf_model_id)
|
| 17 |
+
tokenizerZephyr = AutoTokenizer.from_pretrained(hf_model_id, legacy=False)
|
| 18 |
+
generation_config, unused_kwargs = GenerationConfig.from_pretrained(hf_model_id, max_new_tokens=200, temperature=0.7, return_unused_kwargs=True)
|
| 19 |
+
|
| 20 |
+
model.generation_config = generation_config
|
| 21 |
+
|
| 22 |
+
pipe = pipeline(
|
| 23 |
+
"text-generation",
|
| 24 |
+
model=model,
|
| 25 |
+
tokenizer=tokenizerZephyr,
|
| 26 |
+
)
|
| 27 |
+
pipe(prompt)
|
| 28 |
|
| 29 |
|
| 30 |
def useZephyr(prompt):
|
|
|
|
| 36 |
{"role": "user", "content": prompt},
|
| 37 |
]
|
| 38 |
# https://huggingface.co/docs/transformers/main/en/chat_templating
|
| 39 |
+
outputs = pipe(prompt)
|
|
|
|
|
|
|
| 40 |
|
|
|
|
|
|
|
| 41 |
return outputs[0]["generated_text"]
|
| 42 |
|
| 43 |
|
|
|
|
| 66 |
|
| 67 |
|
| 68 |
input_prompt = gr.Textbox(label="Prompt", value="photographer")
|
| 69 |
+
input_maxtokens = gr.Textbox(label="Max tokens", value="150")
|
| 70 |
output_component = gr.Textbox(label="Output")
|
| 71 |
examples = [["photographer"], ["developer"], ["teacher"], [
|
| 72 |
"human resources staff"], ["recipe for ham croquettes"]]
|
| 73 |
description = ""
|
| 74 |
+
PerfectGPT = gr.Interface(useZephyr, inputs=[input_prompt, input_maxtokens], outputs=output_component,
|
| 75 |
examples=examples, title="🗿 PerfectGPT v1 🗿", description=description)
|
| 76 |
|
| 77 |
+
PerfectGPT.launch()
|