added application - Adithya S K
Browse files- TaoGPT-embeddings/put_your_embeddings_here +0 -0
- app.py +153 -0
- requirements.txt +13 -0
- style.css +16 -0
TaoGPT-embeddings/put_your_embeddings_here
ADDED
File without changes
|
app.py
ADDED
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from huggingface_hub import InferenceClient
|
2 |
+
import gradio as gr
|
3 |
+
from langchain.embeddings import HuggingFaceEmbeddings
|
4 |
+
from langchain.vectorstores import FAISS
|
5 |
+
|
6 |
+
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
7 |
+
vector_store = FAISS.load_local("TaoGPT-Embeddings", embeddings)
|
8 |
+
|
9 |
+
client = InferenceClient(
|
10 |
+
"mistralai/Mistral-7B-Instruct-v0.1"
|
11 |
+
)
|
12 |
+
|
13 |
+
NOMIC = """
|
14 |
+
<!DOCTYPE html>
|
15 |
+
<html>
|
16 |
+
<head>
|
17 |
+
<title>TaoGPT - DataMap</title>
|
18 |
+
<style>
|
19 |
+
iframe {
|
20 |
+
width: 100%;
|
21 |
+
height: 600px; /* You can adjust the height as needed */
|
22 |
+
border: 0;
|
23 |
+
}
|
24 |
+
</style>
|
25 |
+
</head>
|
26 |
+
<body>
|
27 |
+
<iframe
|
28 |
+
src="https://atlas.nomic.ai/map/a59e104a-e4d0-4701-bbd9-3d552aae92a2/a3a2aacd-0787-4389-863a-ab3670015367?xs=-41.70341&xf=41.36850&ys=-23.57587&yf=23.20673"
|
29 |
+
></iframe>
|
30 |
+
</body>
|
31 |
+
</html>
|
32 |
+
"""
|
33 |
+
RAG = True
|
34 |
+
|
35 |
+
def format_prompt(message, history):
|
36 |
+
global RAG
|
37 |
+
if RAG == True:
|
38 |
+
results = vector_store.similarity_search(message ,k=3)
|
39 |
+
context = [result.page_content for result in results]
|
40 |
+
context = "\n\n".join(context)
|
41 |
+
print(context)
|
42 |
+
prompt = "<s>"
|
43 |
+
for user_prompt, bot_response in history:
|
44 |
+
prompt += f"[INST] {user_prompt} [/INST]"
|
45 |
+
prompt += f" {bot_response}</s> "
|
46 |
+
prompt += f"[INST]Given the following Information:\n{context} \n answer the following question {message} [/INST]"
|
47 |
+
return prompt
|
48 |
+
else:
|
49 |
+
prompt = "<s>"
|
50 |
+
for user_prompt, bot_response in history:
|
51 |
+
prompt += f"[INST] {user_prompt} [/INST]"
|
52 |
+
prompt += f" {bot_response}</s> "
|
53 |
+
prompt += f"[INST] {message} [/INST]"
|
54 |
+
return prompt
|
55 |
+
|
56 |
+
|
57 |
+
def generate(
|
58 |
+
prompt, history, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
|
59 |
+
):
|
60 |
+
temperature = float(temperature)
|
61 |
+
if temperature < 1e-2:
|
62 |
+
temperature = 1e-2
|
63 |
+
top_p = float(top_p)
|
64 |
+
|
65 |
+
generate_kwargs = dict(
|
66 |
+
temperature=temperature,
|
67 |
+
max_new_tokens=max_new_tokens,
|
68 |
+
top_p=top_p,
|
69 |
+
repetition_penalty=repetition_penalty,
|
70 |
+
do_sample=True,
|
71 |
+
seed=42,
|
72 |
+
)
|
73 |
+
|
74 |
+
formatted_prompt = format_prompt(prompt, history)
|
75 |
+
|
76 |
+
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
77 |
+
output = ""
|
78 |
+
|
79 |
+
for response in stream:
|
80 |
+
output += response.token.text
|
81 |
+
yield output
|
82 |
+
return output
|
83 |
+
|
84 |
+
|
85 |
+
additional_inputs=[
|
86 |
+
gr.Slider(
|
87 |
+
label="Temperature",
|
88 |
+
value=0.9,
|
89 |
+
minimum=0.0,
|
90 |
+
maximum=1.0,
|
91 |
+
step=0.05,
|
92 |
+
interactive=True,
|
93 |
+
info="Higher values produce more diverse outputs",
|
94 |
+
),
|
95 |
+
gr.Slider(
|
96 |
+
label="Max new tokens",
|
97 |
+
value=256,
|
98 |
+
minimum=0,
|
99 |
+
maximum=1048,
|
100 |
+
step=64,
|
101 |
+
interactive=True,
|
102 |
+
info="The maximum numbers of new tokens",
|
103 |
+
),
|
104 |
+
gr.Slider(
|
105 |
+
label="Top-p (nucleus sampling)",
|
106 |
+
value=0.90,
|
107 |
+
minimum=0.0,
|
108 |
+
maximum=1,
|
109 |
+
step=0.05,
|
110 |
+
interactive=True,
|
111 |
+
info="Higher values sample more low-probability tokens",
|
112 |
+
),
|
113 |
+
gr.Slider(
|
114 |
+
label="Repetition penalty",
|
115 |
+
value=1.2,
|
116 |
+
minimum=1.0,
|
117 |
+
maximum=2.0,
|
118 |
+
step=0.05,
|
119 |
+
interactive=True,
|
120 |
+
info="Penalize repeated tokens",
|
121 |
+
)
|
122 |
+
]
|
123 |
+
|
124 |
+
css = """
|
125 |
+
#mkd {
|
126 |
+
height: 500px;
|
127 |
+
overflow: auto;
|
128 |
+
border: 1px solid #ccc;
|
129 |
+
}
|
130 |
+
"""
|
131 |
+
|
132 |
+
|
133 |
+
|
134 |
+
with gr.Blocks(css=css) as demo:
|
135 |
+
# gr.HTML("<h1><center>Mistral 7B Instruct<h1><center>")
|
136 |
+
# gr.HTML("<h3><center>In this demo, you can chat with <a href='https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.1'>Mistral-7B-Instruct</a> model. 💬<h3><center>")
|
137 |
+
# gr.HTML("<h3><center>Learn more about the model <a href='https://huggingface.co/docs/transformers/main/model_doc/mistral'>here</a>. 📚<h3><center>")
|
138 |
+
gr.HTML("<h1><center>TaoGPT<center></h1>")
|
139 |
+
gr.HTML("<h3><center>TaoGPT is Fine-tuned Mistal-7B model on TaoScience related Information Check out- <a href='https://github.com/agencyxr/taogpt7B'>Github Repo</a> For More Information. 💬<h3><center>")
|
140 |
+
with gr.Row():
|
141 |
+
with gr.Column():
|
142 |
+
gr.HTML("<h3>Chat with TaoGPT</h3>")
|
143 |
+
gr.ChatInterface(
|
144 |
+
generate,
|
145 |
+
additional_inputs=additional_inputs,
|
146 |
+
examples=[["What is TaoScience"], ["Give me a Summary about TaoScience"]]
|
147 |
+
)
|
148 |
+
RAG_Checkbox = gr.Checkbox(label="Use Retrival Augmented Generation" , value=True , interactive=False)
|
149 |
+
with gr.Column():
|
150 |
+
gr.HTML("<h3>Look into the Dataset we used to Finetune our Model</h3>")
|
151 |
+
gr.HTML(NOMIC)
|
152 |
+
|
153 |
+
demo.queue(concurrency_count=75, max_size=100).launch(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
langchain
|
2 |
+
# faiss-gpu
|
3 |
+
faiss-cpu
|
4 |
+
torch==2.0.0
|
5 |
+
accelerate==0.23.0
|
6 |
+
bitsandbytes==0.41.1
|
7 |
+
gradio==3.48.0
|
8 |
+
protobuf==3.20.3
|
9 |
+
scipy==1.11.2
|
10 |
+
sentencepiece==0.1.99
|
11 |
+
spaces==0.16.1
|
12 |
+
transformers==4.34.0
|
13 |
+
sentence-transformers
|
style.css
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
h1 {
|
2 |
+
text-align: center;
|
3 |
+
}
|
4 |
+
|
5 |
+
#duplicate-button {
|
6 |
+
margin: auto;
|
7 |
+
color: white;
|
8 |
+
background: #1565c0;
|
9 |
+
border-radius: 100vh;
|
10 |
+
}
|
11 |
+
|
12 |
+
.contain {
|
13 |
+
max-width: 900px;
|
14 |
+
margin: auto;
|
15 |
+
padding-top: 1.5rem;
|
16 |
+
}
|