tamatwi commited on
Commit
6f82200
·
verified ·
1 Parent(s): 11eb020

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -23
app.py CHANGED
@@ -1,32 +1,23 @@
1
- import os
2
  import gradio as gr
3
- from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
4
 
5
- messages = [
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
- model_name = "SakanaAI/DiscoPOP-zephyr-7b-gemma" # Sakana AIのモデル名を指定
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
- gr.Textbox(label="プロンプト", placeholder="ここに日本語のプロンプトを入力してください"),
27
- gr.Slider(minimum=10, maximum=200, value=50, step=1, label="最大長")
28
- ],
29
- outputs=gr.Textbox(label="生成されたテキスト")
30
  )
31
 
32
- iface.launch()
 
 
 
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()