Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,30 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import pipeline
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
"text-generation",
|
| 7 |
-
model=
|
| 8 |
-
|
|
|
|
| 9 |
do_sample=True,
|
| 10 |
temperature=0.7
|
| 11 |
)
|
| 12 |
|
| 13 |
def chat(history, user_input):
|
| 14 |
-
response =
|
| 15 |
history.append((user_input, response))
|
| 16 |
return history, ""
|
| 17 |
|
| 18 |
with gr.Blocks() as demo:
|
| 19 |
-
gr.Markdown("## 日本語文章の要約・質問チャット(軽量
|
| 20 |
-
|
| 21 |
chatbot = gr.Chatbot(height=500)
|
| 22 |
-
text_input = gr.Textbox(
|
| 23 |
-
label="ここに文章を貼り付けて質問してください",
|
| 24 |
-
placeholder="例:この文章を要約して、など"
|
| 25 |
-
)
|
| 26 |
|
| 27 |
-
text_input.submit(
|
| 28 |
-
chat,
|
| 29 |
-
inputs=[chatbot, text_input],
|
| 30 |
-
outputs=[chatbot, text_input]
|
| 31 |
-
)
|
| 32 |
|
| 33 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 3 |
|
| 4 |
+
model_name = "cyberagent/open-calm-1b"
|
| 5 |
+
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
pipe = pipeline(
|
| 10 |
"text-generation",
|
| 11 |
+
model=model,
|
| 12 |
+
tokenizer=tokenizer,
|
| 13 |
+
max_new_tokens=100,
|
| 14 |
do_sample=True,
|
| 15 |
temperature=0.7
|
| 16 |
)
|
| 17 |
|
| 18 |
def chat(history, user_input):
|
| 19 |
+
response = pipe(user_input)[0]["generated_text"]
|
| 20 |
history.append((user_input, response))
|
| 21 |
return history, ""
|
| 22 |
|
| 23 |
with gr.Blocks() as demo:
|
| 24 |
+
gr.Markdown("## 日本語文章の要約・質問チャット(超軽量版)")
|
|
|
|
| 25 |
chatbot = gr.Chatbot(height=500)
|
| 26 |
+
text_input = gr.Textbox(label="文章を入力してください")
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
text_input.submit(chat, [chatbot, text_input], [chatbot, text_input])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
demo.launch()
|