File size: 2,690 Bytes
9c9cad4
 
1d3932d
8db4f2f
 
 
 
 
75c2786
9c9cad4
75c2786
 
 
 
9c9cad4
75c2786
 
9c9cad4
75c2786
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9c9cad4
75c2786
 
 
 
9c9cad4
75c2786
9c9cad4
75c2786
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9c9cad4
 
 
 
75c2786
0e9bf6e
 
 
 
 
 
 
 
 
 
 
 
 
 
9c9cad4
75c2786
0e9bf6e
 
 
 
 
 
 
 
 
75c2786
0e9bf6e
 
9c9cad4
0e9bf6e
9c9cad4
0e9bf6e
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import gradio as gr

from load_model import load_Auto
from load_push import all_files
from retriever import *
from retrieve_docs import *
from make_chain_model import make_chain_llm
from make_answer import *
from transformers import TextStreamer

llm = load_Auto()
pinecone,bm25 = all_files('files')
retriever=retriever(pinecone,bm25)
rag_chain = make_chain_llm(retriever,llm)

def response(message, history):
    return rag_chain.invoke(message)

# def talk(,history):
#     # k = 1 # number of retrieved documents
#     # scores , retrieved_documents = search(prompt, k)
#     # formatted_prompt = format_prompt(prompt,retrieved_documents,k)
#     # formatted_prompt = formatted_prompt[:2000] # to avoid GPU OOM
    
#     messages =[
#     {"role": "system", "content": f"{PROMPT}"},
#     {}
#     {"role": "user", "content": f"{instruction}"}
#     ]
    
#     # tell the model to generate
#     input_ids = tokenizer.apply_chat_template(
#     messages,
#     add_generation_prompt=True,
#     return_tensors="pt"
#     ).to(model.device)

#     terminators = [
#     tokenizer.eos_token_id,
#     tokenizer.convert_tokens_to_ids("<|eot_id|>")
#     ]

#     text_streamer = TextStreamer(tokenizer)

#     outputs = model.generate(
#     input_ids,
#     max_new_tokens=4096,
#     eos_token_id=terminators,
#     do_sample=True,
#     streamer = text_streamer,
#     temperature=0.6,
#     top_p=0.9,
#     repetition_penalty = 1.1
#     )
#     response = []
#     for text in streamer:
#         response.append(outputs)
#         print(response)
#         yield "".join(response)
        

"""
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
"""

TITLE = "FUT FUT Chatbot"

DESCRIPTION = """
'ํ•ด์š”'์ฒด๋ฅผ ์‚ฌ์šฉํ•˜๋ฉฐ ์นœ์ ˆํ•˜๊ฒŒ ๋‹ตํ•˜๋Š” ํ’‹ํ’‹์ด ์ฑ—๋ด‡.
A rag pipeline with a chatbot feature
Resources used to build this project :
* embedding model : https://huggingface.co/BM-K/KoSimCSE-roberta-multitask
* dataset : https://huggingface.co/datasets/Dongwookss/q_a_korean_futsal
* vector DB : PINECONE
* chatbot : https://huggingface.co/Dongwookss/small_fut_final
"""

Examples = [['์‹œํฅ ํ’‹์‚ด ๊ตฌ์žฅ ์ถ”์ฒœํ•ด์ค˜'],['ํ’‹์‚ด ๊ฒฝ๊ธฐ ๊ทœ์น™ ์„ค๋ช…ํ•ด์ค˜'], ['ํ’‹์‚ด ๊ฒฝ๊ธฐ ์‹œ๊ฐ„ ์•Œ๋ ค์ค˜']]

demo = gr.ChatInterface(
    fn=response,
    chatbot=gr.Chatbot(
        show_label=True,
        show_share_button=True,
        show_copy_button=True,
        likeable=True,
        layout="bubble",
        bubble_full_width=False,
    ),
    theme="Soft",
    examples=Examples,
    title=TITLE,
    description=DESCRIPTION,
)
demo.launch(debug=True)

# if __name__ == "__main__":
#     demo.launch()