Spaces:
Sleeping
Sleeping
Commit
·
5e69796
1
Parent(s):
2292936
[add] app
Browse files- app.py +38 -0
- requirements.txt +6 -0
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from vllm import LLM, SamplingParams
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
llm = LLM(model="EQUES/JPharmatron-7B")
|
5 |
+
sampling_params = SamplingParams(temperature=0.0, max_tokens=512)
|
6 |
+
|
7 |
+
# 応答関数
|
8 |
+
def chat_bot(user_input, history):
|
9 |
+
# システムプロンプトを付与して文脈を明確にする
|
10 |
+
prompt = "以下は親切で何でも答えてくれるAIアシスタントとの会話です。\n"
|
11 |
+
for user_msg, bot_msg in history:
|
12 |
+
prompt += f"ユーザー: {user_msg}\nアシスタント: {bot_msg}\n"
|
13 |
+
prompt += f"ユーザー: {user_input}\nアシスタント:"
|
14 |
+
|
15 |
+
outputs = llm.generate(prompt, sampling_params)
|
16 |
+
reply = outputs[0].outputs[0].text.strip()
|
17 |
+
history.append((user_input, reply))
|
18 |
+
return reply, history
|
19 |
+
|
20 |
+
# Gradio UIの構築
|
21 |
+
with gr.Blocks() as demo:
|
22 |
+
gr.Markdown("# 💊 製薬に関する質問をしてみてください。")
|
23 |
+
gr.Markdown("※ あくまでデモとしての利用のみに止めてください。")
|
24 |
+
|
25 |
+
chatbot = gr.Chatbot()
|
26 |
+
msg = gr.Textbox(label="あなたのメッセージを入力してください。")
|
27 |
+
clear = gr.Button("チャット履歴をクリア")
|
28 |
+
|
29 |
+
state = gr.State([])
|
30 |
+
|
31 |
+
def respond(message, history):
|
32 |
+
response, history = chat_bot(message, history)
|
33 |
+
return history, history
|
34 |
+
|
35 |
+
msg.submit(respond, [msg, state], [chatbot, state])
|
36 |
+
clear.click(lambda: ([], []), None, [chatbot, state])
|
37 |
+
|
38 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
accelerate
|
3 |
+
matplotlib
|
4 |
+
streamlit
|
5 |
+
gradio
|
6 |
+
vllm
|