Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,17 +4,15 @@ from huggingface_hub import InferenceClient
|
|
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("Futuresony/future_ai_12_10_2024.gguf")
|
8 |
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
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 |
for val in history:
|
@@ -29,10 +27,10 @@ def respond(
|
|
29 |
|
30 |
for message in client.chat_completion(
|
31 |
messages,
|
32 |
-
max_tokens=
|
33 |
stream=True,
|
34 |
-
temperature=
|
35 |
-
top_p=
|
36 |
):
|
37 |
token = message.choices[0].delta.content
|
38 |
|
@@ -40,16 +38,34 @@ def respond(
|
|
40 |
yield response
|
41 |
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
if __name__ == "__main__":
|
51 |
-
"""
|
52 |
demo.launch()
|
53 |
-
|
54 |
-
|
55 |
-
app.run(debug=True, port=7860)
|
|
|
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(model="Futuresony/future_ai_12_10_2024.gguf")
|
8 |
|
9 |
+
# Set fixed parameters
|
10 |
+
MAX_TOKENS = 512
|
11 |
+
TEMPERATURE = 0.7
|
12 |
+
TOP_P = 0.95
|
13 |
|
14 |
+
|
15 |
+
def respond(message, history: list[tuple[str, str]], system_message):
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
messages = [{"role": "system", "content": system_message}]
|
17 |
|
18 |
for val in history:
|
|
|
27 |
|
28 |
for message in client.chat_completion(
|
29 |
messages,
|
30 |
+
max_tokens=MAX_TOKENS,
|
31 |
stream=True,
|
32 |
+
temperature=TEMPERATURE,
|
33 |
+
top_p=TOP_P,
|
34 |
):
|
35 |
token = message.choices[0].delta.content
|
36 |
|
|
|
38 |
yield response
|
39 |
|
40 |
|
41 |
+
# Gradio interface setup
|
42 |
+
with gr.Blocks() as demo:
|
43 |
+
# Chatbot Interface
|
44 |
+
chatbot = gr.Chatbot()
|
45 |
+
state = gr.State([])
|
46 |
+
system_message = gr.Textbox(
|
47 |
+
value="You are a helpful assistant.",
|
48 |
+
label="System Prompt",
|
49 |
+
placeholder="Enter system instructions here...",
|
50 |
+
)
|
51 |
+
user_message = gr.Textbox(label="Your Message", placeholder="Type your message...")
|
52 |
+
send_button = gr.Button("Send")
|
53 |
|
54 |
+
# Function to handle user inputs and display assistant responses
|
55 |
+
def chat(user_input, chat_history, sys_msg):
|
56 |
+
response_generator = respond(user_input, chat_history, sys_msg)
|
57 |
+
response = ""
|
58 |
+
for partial_response in response_generator:
|
59 |
+
response = partial_response
|
60 |
+
chat_history.append((user_input, response))
|
61 |
+
return chat_history, chat_history
|
62 |
|
63 |
+
send_button.click(
|
64 |
+
chat,
|
65 |
+
inputs=[user_message, state, system_message],
|
66 |
+
outputs=[chatbot, state],
|
67 |
+
)
|
68 |
|
69 |
if __name__ == "__main__":
|
|
|
70 |
demo.launch()
|
71 |
+
|
|
|
|