keita-origin commited on
Commit
a45d4d2
·
verified ·
1 Parent(s): 4e0ab1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -13
app.py CHANGED
@@ -1,17 +1,22 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
- # Use a pipeline as a high-level helper
4
  from transformers import pipeline
5
 
6
- pipe = pipeline("text-generation", model="keita-origin/Da-1.0b")
7
- """
8
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
9
- """
10
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
11
 
12
- def generate_text(prompt):
13
- result = pipe(prompt, max_length=100)
14
- return result[0]["generated_text"]
15
- # Gradioインターフェイスを作成
16
- demo = gr.ChatInterface(fn=generate_text, inputs="text", outputs="text")
17
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
 
 
2
  from transformers import pipeline
3
 
4
+ # モデルの読み込み
5
+ generator = pipeline("text-generation", model="keita-origin/Da-1.0b")
 
 
 
6
 
7
+ # チャット履歴を保持する関数
8
+ def chatbot(message, history):
9
+ history.append((message, ""))
10
+ response = generator(message, max_length=100)[0]["generated_text"]
11
+ history[-1] = (message, response)
12
+ return history
13
+
14
+ # ChatGPT 風のインターフェース
15
+ chatbot_ui = gr.ChatInterface(
16
+ chatbot,
17
+ title="AI Chatbot",
18
+ description="Hugging Face のモデルを使った対話型 AI",
19
+ )
20
+
21
+ # 実行
22
+ chatbot_ui.launch()