Spaces:
Sleeping
Sleeping
Gyu-min Nigel Lee
commited on
Commit
•
ee17265
1
Parent(s):
55ad9bf
updated the app
Browse files
app.py
CHANGED
@@ -1,43 +1,38 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
from
|
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 |
-
|
12 |
-
|
13 |
-
|
14 |
max_tokens,
|
15 |
temperature,
|
16 |
top_p,
|
17 |
):
|
18 |
-
messages = [{"role": "
|
19 |
-
|
20 |
-
|
21 |
-
if val[0]:
|
22 |
-
messages.append({"role": "user", "content": val[0]})
|
23 |
-
if val[1]:
|
24 |
-
messages.append({"role": "assistant", "content": val[1]})
|
25 |
-
|
26 |
-
messages.append({"role": "user", "content": message})
|
27 |
-
|
28 |
-
response = ""
|
29 |
|
30 |
-
|
31 |
messages,
|
32 |
max_tokens=max_tokens,
|
33 |
stream=True,
|
34 |
temperature=temperature,
|
35 |
top_p=top_p,
|
36 |
-
)
|
37 |
-
|
38 |
|
39 |
-
response += token
|
40 |
-
yield response
|
41 |
|
42 |
"""
|
43 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
@@ -45,9 +40,11 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
|
|
45 |
demo = gr.ChatInterface(
|
46 |
respond,
|
47 |
additional_inputs=[
|
48 |
-
gr.Textbox(value="
|
|
|
|
|
49 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
50 |
-
gr.Slider(minimum=0.1, maximum=
|
51 |
gr.Slider(
|
52 |
minimum=0.1,
|
53 |
maximum=1.0,
|
@@ -60,4 +57,4 @@ demo = gr.ChatInterface(
|
|
60 |
|
61 |
|
62 |
if __name__ == "__main__":
|
63 |
-
demo.launch()
|
|
|
1 |
+
import torch
|
2 |
import gradio as gr
|
3 |
+
from transformers import 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 |
+
pipe = pipeline(
|
10 |
+
model="gyulukeyi/llama3-nallm-qa-8B_240708",
|
11 |
+
torch_dtype=torch.float16,
|
12 |
+
)
|
13 |
|
14 |
|
15 |
def respond(
|
16 |
+
municipality,
|
17 |
+
title,
|
18 |
+
question,
|
19 |
max_tokens,
|
20 |
temperature,
|
21 |
top_p,
|
22 |
):
|
23 |
+
messages = [{"role": "municipality", "content": municipality}]
|
24 |
+
messages.append({"role": "title", "content": title})
|
25 |
+
messages.append({"role": "question", "content": question})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
+
output = pipe(
|
28 |
messages,
|
29 |
max_tokens=max_tokens,
|
30 |
stream=True,
|
31 |
temperature=temperature,
|
32 |
top_p=top_p,
|
33 |
+
)
|
34 |
+
return output[0]["generated_text"]
|
35 |
|
|
|
|
|
36 |
|
37 |
"""
|
38 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
|
40 |
demo = gr.ChatInterface(
|
41 |
respond,
|
42 |
additional_inputs=[
|
43 |
+
gr.Textbox(value="서울특별시", label="municipality"),
|
44 |
+
gr.Textbox(value="", label="title"),
|
45 |
+
gr.Textbox(value="", label="question"),
|
46 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
47 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.5, step=0.05, label="Temperature"),
|
48 |
gr.Slider(
|
49 |
minimum=0.1,
|
50 |
maximum=1.0,
|
|
|
57 |
|
58 |
|
59 |
if __name__ == "__main__":
|
60 |
+
demo.launch()
|