h1r41 commited on
Commit
f7c29f8
1 Parent(s): 267cc95

initial commit

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +43 -0
  3. requirements.txt +0 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ /env
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from llama_cpp import Llama
4
+ from huggingface_hub import hf_hub_download
5
+
6
+ # Hugging FaceのAPIトークンを設定
7
+ os.environ["HUGGINGFACE_TOKEN"] = os.getenv("HUGGINGFACE_TOKEN")
8
+
9
+ model_name_or_path = "TheBloke/OpenBuddy-Llama2-13B-v11.1-GGUF"
10
+ model_basename = "openbuddy-llama2-13b-v11.1.Q2_K.gguf"
11
+
12
+ model_path = hf_hub_download(repo_id=model_name_or_path, filename=model_basename, revision="main")
13
+ llama = Llama(model_path)
14
+
15
+ def predict(message, history):
16
+ messages = []
17
+ for human_content, system_content in history:
18
+ message_human = {
19
+ "role": "user",
20
+ "content": human_content + "\n",
21
+ }
22
+ message_system = {
23
+ "role": "system",
24
+ "content": system_content + "\n",
25
+ }
26
+ messages.append(message_human)
27
+ messages.append(message_system)
28
+ message_human = {
29
+ "role": "user",
30
+ "content": message + "\n",
31
+ }
32
+ messages.append(message_human)
33
+ # Llamaでの回答を取得(ストリーミングオン)
34
+ streamer = llama.create_chat_completion(messages, stream=True)
35
+
36
+ partial_message = ""
37
+ for msg in streamer:
38
+ message = msg['choices'][0]['delta']
39
+ if 'content' in message:
40
+ partial_message += message['content']
41
+ yield partial_message
42
+
43
+ gr.ChatInterface(predict).launch(enable_queue=True)
requirements.txt ADDED
Binary file (2.25 kB). View file