Spaces:
Sleeping
Sleeping
TeleologyHI
commited on
Commit
·
cb9d075
1
Parent(s):
c7565e0
Fix app.py merge conflicts
Browse files
app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
import gradio as gr
|
2 |
-
<<<<<<< HEAD
|
3 |
from src.model.him_model import HIMModel
|
4 |
from src.core.config import HIMConfig
|
5 |
|
@@ -8,95 +7,40 @@ def initialize_model():
|
|
8 |
model = HIMModel(config)
|
9 |
return model
|
10 |
|
11 |
-
def
|
|
|
|
|
|
|
|
|
|
|
12 |
input_data = {
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
17 |
}
|
18 |
|
19 |
-
result = model.
|
20 |
-
return
|
21 |
|
22 |
model = initialize_model()
|
23 |
|
24 |
interface = gr.Interface(
|
25 |
-
fn=
|
26 |
inputs=[
|
27 |
-
gr.Textbox(label="
|
28 |
-
gr.
|
29 |
-
gr.
|
30 |
-
|
31 |
-
|
32 |
-
gr.Textbox(label="HIM Response"),
|
33 |
-
gr.Plot(label="Consciousness State Visualization")
|
34 |
],
|
|
|
35 |
title="Hybrid Intelligence Matrix (HIM)",
|
36 |
description="Interact with the HIM system for advanced cognitive processing"
|
37 |
)
|
38 |
-
=======
|
39 |
-
from huggingface_hub import InferenceClient
|
40 |
-
|
41 |
-
"""
|
42 |
-
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
|
43 |
-
"""
|
44 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
45 |
-
|
46 |
-
|
47 |
-
def respond(
|
48 |
-
message,
|
49 |
-
history: list[tuple[str, str]],
|
50 |
-
system_message,
|
51 |
-
max_tokens,
|
52 |
-
temperature,
|
53 |
-
top_p,
|
54 |
-
):
|
55 |
-
messages = [{"role": "system", "content": system_message}]
|
56 |
-
|
57 |
-
for val in history:
|
58 |
-
if val[0]:
|
59 |
-
messages.append({"role": "user", "content": val[0]})
|
60 |
-
if val[1]:
|
61 |
-
messages.append({"role": "assistant", "content": val[1]})
|
62 |
-
|
63 |
-
messages.append({"role": "user", "content": message})
|
64 |
-
|
65 |
-
response = ""
|
66 |
-
|
67 |
-
for message in client.chat_completion(
|
68 |
-
messages,
|
69 |
-
max_tokens=max_tokens,
|
70 |
-
stream=True,
|
71 |
-
temperature=temperature,
|
72 |
-
top_p=top_p,
|
73 |
-
):
|
74 |
-
token = message.choices[0].delta.content
|
75 |
-
|
76 |
-
response += token
|
77 |
-
yield response
|
78 |
-
|
79 |
-
|
80 |
-
"""
|
81 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
82 |
-
"""
|
83 |
-
demo = gr.ChatInterface(
|
84 |
-
respond,
|
85 |
-
additional_inputs=[
|
86 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
87 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
88 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
89 |
-
gr.Slider(
|
90 |
-
minimum=0.1,
|
91 |
-
maximum=1.0,
|
92 |
-
value=0.95,
|
93 |
-
step=0.05,
|
94 |
-
label="Top-p (nucleus sampling)",
|
95 |
-
),
|
96 |
-
],
|
97 |
-
)
|
98 |
-
|
99 |
|
100 |
if __name__ == "__main__":
|
101 |
-
|
102 |
-
>>>>>>> origin/main
|
|
|
1 |
import gradio as gr
|
|
|
2 |
from src.model.him_model import HIMModel
|
3 |
from src.core.config import HIMConfig
|
4 |
|
|
|
7 |
model = HIMModel(config)
|
8 |
return model
|
9 |
|
10 |
+
def chat(message: str,
|
11 |
+
system_message: str = "You are a friendly Chatbot.",
|
12 |
+
max_tokens: int = 512,
|
13 |
+
temperature: float = 0.7,
|
14 |
+
top_p: float = 0.95):
|
15 |
+
|
16 |
input_data = {
|
17 |
+
"message": message,
|
18 |
+
"system_message": system_message,
|
19 |
+
"parameters": {
|
20 |
+
"max_tokens": max_tokens,
|
21 |
+
"temperature": temperature,
|
22 |
+
"top_p": top_p
|
23 |
+
}
|
24 |
}
|
25 |
|
26 |
+
result = model.generate_response(input_data)
|
27 |
+
return result["response"]
|
28 |
|
29 |
model = initialize_model()
|
30 |
|
31 |
interface = gr.Interface(
|
32 |
+
fn=chat,
|
33 |
inputs=[
|
34 |
+
gr.Textbox(label="Message"),
|
35 |
+
gr.Textbox(label="System Message", value="You are a friendly Chatbot."),
|
36 |
+
gr.Slider(minimum=1, maximum=2048, value=512, label="Max Tokens"),
|
37 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.7, label="Temperature"),
|
38 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, label="Top P")
|
|
|
|
|
39 |
],
|
40 |
+
outputs=gr.Textbox(label="HIM Response"),
|
41 |
title="Hybrid Intelligence Matrix (HIM)",
|
42 |
description="Interact with the HIM system for advanced cognitive processing"
|
43 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
if __name__ == "__main__":
|
46 |
+
interface.launch()
|
|