Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,23 @@
|
|
1 |
-
import
|
2 |
import gradio as gr
|
3 |
-
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
4 |
|
5 |
-
|
6 |
-
{"role": "user", "content": "Who are you?"},
|
7 |
-
]
|
8 |
pipe = pipeline("text-generation", model="SakanaAI/DiscoPOP-zephyr-7b-gemma")
|
9 |
-
pipe(messages)
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
# トークナイザーとパイプラインの設定
|
15 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
16 |
-
model = AutoModelForCausalLM.from_pretrained(model_name)
|
17 |
-
generator = pipeline('text-generation', model=model, tokenizer=tokenizer, device=-1) # device=-1はCPUを使用する設定
|
18 |
-
|
19 |
-
def generate_text(prompt, max_length):
|
20 |
-
result = generator(prompt, max_length=max_length, num_return_sequences=1)
|
21 |
return result[0]['generated_text']
|
22 |
|
|
|
23 |
iface = gr.Interface(
|
24 |
-
fn=generate_text,
|
25 |
-
inputs=
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
outputs=gr.Textbox(label="生成されたテキスト")
|
30 |
)
|
31 |
|
32 |
-
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
+
# Initialize the text generation pipeline
|
|
|
|
|
5 |
pipe = pipeline("text-generation", model="SakanaAI/DiscoPOP-zephyr-7b-gemma")
|
|
|
6 |
|
7 |
+
# Define a function to generate text based on user input
|
8 |
+
def generate_text(prompt):
|
9 |
+
result = pipe(prompt, max_length=50, num_return_sequences=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
return result[0]['generated_text']
|
11 |
|
12 |
+
# Create a Gradio interface
|
13 |
iface = gr.Interface(
|
14 |
+
fn=generate_text,
|
15 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter your prompt here..."),
|
16 |
+
outputs="text",
|
17 |
+
title="Text Generation with DiscoPOP-zephyr-7b-gemma",
|
18 |
+
description="Enter a prompt and the model will generate a continuation of the text."
|
|
|
19 |
)
|
20 |
|
21 |
+
# Launch the interface
|
22 |
+
if __name__ == "__main__":
|
23 |
+
iface.launch()
|