Spaces:
Sleeping
Sleeping
first
Browse files
app.py
CHANGED
@@ -1,11 +1,8 @@
|
|
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 |
message,
|
@@ -15,39 +12,32 @@ def respond(
|
|
15 |
temperature,
|
16 |
top_p,
|
17 |
):
|
18 |
-
|
19 |
-
|
20 |
-
for
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
response = ""
|
29 |
-
|
30 |
-
for message in client.chat_completion(
|
31 |
-
messages,
|
32 |
-
max_tokens=max_tokens,
|
33 |
-
stream=True,
|
34 |
temperature=temperature,
|
35 |
top_p=top_p,
|
36 |
-
|
37 |
-
|
38 |
|
39 |
-
|
40 |
-
|
|
|
|
|
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 |
-
gr.Slider(minimum=1, maximum=
|
50 |
-
gr.Slider(minimum=0.1, maximum=
|
51 |
gr.Slider(
|
52 |
minimum=0.1,
|
53 |
maximum=1.0,
|
@@ -58,6 +48,5 @@ demo = gr.ChatInterface(
|
|
58 |
],
|
59 |
)
|
60 |
|
61 |
-
|
62 |
if __name__ == "__main__":
|
63 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
# Load the model
|
5 |
+
pipe = pipeline("text-generation", model="KoboldAI/fairseq-dense-13B-Shinen")
|
6 |
|
7 |
def respond(
|
8 |
message,
|
|
|
12 |
temperature,
|
13 |
top_p,
|
14 |
):
|
15 |
+
# Construct the prompt from history and current message
|
16 |
+
prompt = system_message + "\n\n"
|
17 |
+
for user_msg, bot_msg in history:
|
18 |
+
prompt += f"Human: {user_msg}\nAI: {bot_msg}\n"
|
19 |
+
prompt += f"Human: {message}\nAI:"
|
20 |
+
|
21 |
+
# Generate response
|
22 |
+
response = pipe(
|
23 |
+
prompt,
|
24 |
+
max_length=len(prompt.split()) + max_tokens,
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
temperature=temperature,
|
26 |
top_p=top_p,
|
27 |
+
do_sample=True,
|
28 |
+
)[0]['generated_text']
|
29 |
|
30 |
+
# Extract only the AI's response
|
31 |
+
ai_response = response.split("AI:")[-1].strip()
|
32 |
+
|
33 |
+
return ai_response
|
34 |
|
|
|
|
|
|
|
35 |
demo = gr.ChatInterface(
|
36 |
respond,
|
37 |
additional_inputs=[
|
38 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
39 |
+
gr.Slider(minimum=1, maximum=512, value=256, step=1, label="Max new tokens"),
|
40 |
+
gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature"),
|
41 |
gr.Slider(
|
42 |
minimum=0.1,
|
43 |
maximum=1.0,
|
|
|
48 |
],
|
49 |
)
|
50 |
|
|
|
51 |
if __name__ == "__main__":
|
52 |
demo.launch()
|