Spaces:
Running
Running
Paulie-Aditya
commited on
Commit
·
5a45b9a
1
Parent(s):
f90f6d9
Update space
Browse files- .gitignore +2 -0
- .vscode/settings.json +3 -0
- app.py +38 -27
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
*.venv
|
2 |
+
*.gitattributes
|
.vscode/settings.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"taipyStudio.gUI.elementsFilePaths": []
|
3 |
+
}
|
app.py
CHANGED
@@ -1,50 +1,60 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
|
|
3 |
|
4 |
"""
|
5 |
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
|
6 |
"""
|
7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
def respond(
|
11 |
-
message,
|
12 |
-
history: list[tuple[str, str]],
|
13 |
-
system_message,
|
14 |
-
max_tokens,
|
15 |
-
temperature,
|
16 |
-
top_p,
|
17 |
-
):
|
18 |
-
messages = [{"role": "system", "content": system_message}]
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
|
|
|
|
|
|
|
|
|
27 |
|
28 |
-
|
29 |
|
30 |
-
|
31 |
-
messages,
|
32 |
-
max_tokens=max_tokens,
|
33 |
-
stream=True,
|
34 |
-
temperature=temperature,
|
35 |
-
top_p=top_p,
|
36 |
-
):
|
37 |
-
token = message.choices[0].delta.content
|
38 |
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
|
43 |
"""
|
44 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
45 |
"""
|
|
|
|
|
46 |
demo = gr.ChatInterface(
|
47 |
-
respond,
|
48 |
additional_inputs=[
|
49 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
50 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
@@ -61,4 +71,5 @@ demo = gr.ChatInterface(
|
|
61 |
|
62 |
|
63 |
if __name__ == "__main__":
|
|
|
64 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
4 |
|
5 |
"""
|
6 |
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
|
7 |
"""
|
8 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
9 |
|
10 |
+
class Assistant:
|
11 |
+
def __init__(self, model_name="ContactDoctor/Bio-Medical-Llama-3-8B"):
|
12 |
+
self.tokenizer = AutoTokenizer.from_pretrained(model_name)
|
13 |
+
self.model = AutoModelForCausalLM.from_pretrained(model_name)
|
14 |
+
self.pipe = pipeline("text-generation", model="ContactDoctor/Bio-Medical-Llama-3-8B")
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
def respond(
|
18 |
+
self,
|
19 |
+
message,
|
20 |
+
history: list[tuple[str, str]],
|
21 |
+
system_message,
|
22 |
+
max_tokens,
|
23 |
+
temperature,
|
24 |
+
top_p,
|
25 |
+
):
|
26 |
+
messages = [{"role": "system", "content": system_message}]
|
27 |
|
28 |
+
for val in history:
|
29 |
+
if val[0]:
|
30 |
+
messages.append({"role": "user", "content": val[0]})
|
31 |
+
if val[1]:
|
32 |
+
messages.append({"role": "assistant", "content": val[1]})
|
33 |
|
34 |
+
messages.append({"role": "user", "content": message})
|
35 |
|
36 |
+
response = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
+
for message in client.chat_completion(
|
39 |
+
messages,
|
40 |
+
max_tokens=max_tokens,
|
41 |
+
stream=True,
|
42 |
+
temperature=temperature,
|
43 |
+
top_p=top_p,
|
44 |
+
):
|
45 |
+
token = message.choices[0].delta.content
|
46 |
+
|
47 |
+
response += token
|
48 |
+
yield response
|
49 |
|
50 |
|
51 |
"""
|
52 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
53 |
"""
|
54 |
+
assistant = Assistant()
|
55 |
+
|
56 |
demo = gr.ChatInterface(
|
57 |
+
assistant.respond,
|
58 |
additional_inputs=[
|
59 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
60 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
|
|
71 |
|
72 |
|
73 |
if __name__ == "__main__":
|
74 |
+
# Assistant()
|
75 |
demo.launch()
|