tamatwi commited on
Commit
d6e1ddc
·
verified ·
1 Parent(s): d3ff6b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -2
app.py CHANGED
@@ -28,8 +28,51 @@
28
 
29
 
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  import gradio as gr
32
- from transformers import pipeline, AutoTokenizer
 
 
 
 
 
 
 
 
 
33
 
34
  # 日本語モデルを指定
35
  model_name = "SakanaAI/EvoLLM-JP-v1-7B"
@@ -51,4 +94,6 @@ iface = gr.Interface(
51
  outputs=gr.Textbox(label="生成されたテキスト")
52
  )
53
 
54
- iface.launch()
 
 
 
28
 
29
 
30
 
31
+ # import gradio as gr
32
+ # from transformers import pipeline, AutoTokenizer
33
+
34
+ # 日本語モデルを指定
35
+ model_name = "SakanaAI/EvoLLM-JP-v1-7B"
36
+
37
+ # トークナイザーとパイプラインの設定
38
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
39
+ generator = pipeline('text-generation', model=model_name, tokenizer=tokenizer, device=-1) # device=0はGPUを使用する設定
40
+
41
+ def generate_text(prompt, max_length):
42
+ result = generator(prompt, max_length=max_length, num_return_sequences=1)
43
+ return result[0]['generated_text']
44
+
45
+ iface = gr.Interface(
46
+ fn=generate_text,
47
+ inputs=[
48
+ gr.Textbox(label="プロンプト", placeholder="ここに日本語のプロンプトを入力してください"),
49
+ gr.Slider(minimum=10, maximum=200, value=50, step=1, label="最大長")
50
+ ],
51
+ outputs=gr.Textbox(label="生成されたテキスト")
52
+ )
53
+
54
+ iface.launch()
55
+
56
+
57
+
58
+ # gemma2
59
+
60
+
61
+ import os
62
+ from threading import Thread
63
+ from typing import Iterator
64
+
65
  import gradio as gr
66
+ import spaces
67
+ import torch
68
+ from transformers import (
69
+ AutoModelForCausalLM,
70
+ BitsAndBytesConfig,
71
+ GemmaTokenizerFast,
72
+ TextIteratorStreamer,
73
+ pipeline, AutoTokenizer
74
+ )
75
+
76
 
77
  # 日本語モデルを指定
78
  model_name = "SakanaAI/EvoLLM-JP-v1-7B"
 
94
  outputs=gr.Textbox(label="生成されたテキスト")
95
  )
96
 
97
+ iface.launch()
98
+
99
+