Spaces:
Running
on
Zero
Running
on
Zero
Nihal Nayak
commited on
Commit
·
59340b6
1
Parent(s):
a4b5ada
wip: app
Browse files
app.py
CHANGED
@@ -1,63 +1,90 @@
|
|
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(
|
8 |
|
9 |
|
10 |
def respond(
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
top_p,
|
17 |
):
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
for val in history:
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
|
26 |
-
messages.append({"role": "user", "content": message})
|
27 |
|
28 |
-
response = ""
|
29 |
|
30 |
-
for message in client.chat_completion(
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
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
|
44 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
demo = gr.ChatInterface(
|
46 |
respond,
|
47 |
additional_inputs=[
|
48 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
49 |
-
|
50 |
-
gr.Slider(minimum=
|
51 |
-
gr.Slider(
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
),
|
|
|
58 |
],
|
|
|
|
|
59 |
)
|
60 |
|
61 |
|
62 |
if __name__ == "__main__":
|
63 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
+
import gradio as gr
|
4 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
5 |
+
import spaces
|
6 |
|
7 |
"""
|
8 |
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
|
9 |
"""
|
10 |
+
client = InferenceClient()
|
11 |
|
12 |
|
13 |
def respond(
|
14 |
+
context: str,
|
15 |
+
task_type: str,
|
16 |
+
max_tokens: int = 256,
|
17 |
+
temperature: float = 0.5,
|
18 |
+
top_p: float = 0.95,
|
|
|
19 |
):
|
20 |
+
task_type = "extractive question answering"
|
21 |
+
input_text = "<|tasktype|>\n" + task_type.strip()
|
22 |
+
input_text += (
|
23 |
+
"\n<|context|>\n" + context.strip() + "\n<|task|>\n"
|
24 |
+
)
|
25 |
+
|
26 |
+
for token in client.text_generation(input_text, max_tokens=max_tokens, temperature=temperature, top_p=top_p, stream=True):
|
27 |
+
yield token
|
28 |
+
|
29 |
+
# messages = [{"role": "system", "content": system_message}]
|
30 |
|
31 |
+
# for val in history:
|
32 |
+
# if val[0]:
|
33 |
+
# messages.append({"role": "user", "content": val[0]})
|
34 |
+
# if val[1]:
|
35 |
+
# messages.append({"role": "assistant", "content": val[1]})
|
36 |
|
37 |
+
# messages.append({"role": "user", "content": message})
|
38 |
|
39 |
+
# response = ""
|
40 |
|
41 |
+
# for message in client.chat_completion(
|
42 |
+
# messages,
|
43 |
+
# max_tokens=max_tokens,
|
44 |
+
# stream=True,
|
45 |
+
# temperature=temperature,
|
46 |
+
# top_p=top_p,
|
47 |
+
# ):
|
48 |
+
# token = message.choices[0].delta.content
|
49 |
+
|
50 |
+
# response += token
|
51 |
+
# yield response
|
52 |
|
|
|
|
|
53 |
|
54 |
"""
|
55 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
56 |
"""
|
57 |
+
|
58 |
+
description = """
|
59 |
+
This is Bonito.
|
60 |
+
"""
|
61 |
+
|
62 |
+
|
63 |
+
examples = [
|
64 |
+
"Hugging Face, Inc. is a French-American company incorporated under the Delaware General Corporation Law[1] and based in New York City that develops computation tools for building applications using machine learning. It is most notable for its transformers library built for natural language processing applications and its platform that allows users to share machine learning models and datasets and showcase their work.",
|
65 |
+
"In order to make your Space work with ZeroGPU you need to decorate the Python functions that actually require a GPU with @spaces.GPU \n During the time when a decorated function is invoked, the Space will be attributed a GPU, and it will release it upon completion of the function.",
|
66 |
+
"A spectre is haunting Europe – the spectre of communism. All the powers of old Europe have entered into a holy alliance to exorcise this spectre: Pope and Tsar, Metternich and Guizot, French Radicals and German police-spies"
|
67 |
+
]
|
68 |
+
|
69 |
demo = gr.ChatInterface(
|
70 |
respond,
|
71 |
additional_inputs=[
|
72 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
73 |
+
|
74 |
+
# gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
75 |
+
# gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
76 |
+
# gr.Slider(
|
77 |
+
# minimum=0.1,
|
78 |
+
# maximum=1.0,
|
79 |
+
# value=0.95,
|
80 |
+
# step=0.05,
|
81 |
+
# label="Top-p (nucleus sampling)",
|
82 |
+
# ),
|
83 |
],
|
84 |
+
examples=examples,
|
85 |
+
description=description,
|
86 |
)
|
87 |
|
88 |
|
89 |
if __name__ == "__main__":
|
90 |
+
demo.launch()
|