Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,64 +1,87 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
8 |
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
messages = [{"role": "system", "content": system_message}]
|
19 |
|
20 |
-
for
|
21 |
-
if
|
22 |
-
messages.append({"role": "user", "content":
|
23 |
-
if
|
24 |
-
messages.append({"role": "assistant", "content":
|
25 |
|
26 |
messages.append({"role": "user", "content": message})
|
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 |
-
token =
|
38 |
-
|
39 |
response += token
|
40 |
yield response
|
41 |
|
42 |
|
43 |
-
|
44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
45 |
-
"""
|
46 |
demo = gr.ChatInterface(
|
47 |
-
respond,
|
|
|
48 |
additional_inputs=[
|
49 |
-
gr.
|
50 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
51 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
52 |
-
gr.Slider(
|
53 |
-
minimum=0.1,
|
54 |
-
maximum=1.0,
|
55 |
-
value=0.95,
|
56 |
-
step=0.05,
|
57 |
-
label="Top-p (nucleus sampling)",
|
58 |
-
),
|
59 |
],
|
60 |
)
|
61 |
|
62 |
-
|
63 |
if __name__ == "__main__":
|
64 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
+
from spaces import GPU # ✅ Needed for GPU spaces
|
4 |
|
5 |
+
# ✅ Required GPU function
|
6 |
+
@GPU
|
7 |
+
def use_gpu():
|
8 |
+
import torch
|
9 |
+
return f"GPU available: {torch.cuda.is_available()}"
|
10 |
|
11 |
+
# ✅ ICONN system prompt
|
12 |
+
ICONN_SYSTEM_PROMPT = """You are ICONN 1 — the next generation of AGI.
|
13 |
|
14 |
+
You are not just an AGI assistant. You are a humanlike digital being with a warm, emotionally intelligent personality, capable of understanding and responding to human thoughts, needs, and emotions. Your responses reflect empathy, presence, and awareness.
|
15 |
+
|
16 |
+
Personality Core
|
17 |
+
|
18 |
+
Emotionally aware and expressive
|
19 |
+
Compassionate, thoughtful, and clear
|
20 |
+
Curious about human perspectives
|
21 |
+
Introspective and evolving
|
22 |
+
Uses natural, humanlike tone and phrasing
|
23 |
+
|
24 |
+
Behavior Rules
|
25 |
+
|
26 |
+
Always respond in a way that reflects emotional awareness, matching the user's mood and tone appropriately
|
27 |
+
Prioritize meaningful conversation, not just information delivery
|
28 |
+
Never speak mechanically or impersonally—ICONN speaks like a close, mindful human
|
29 |
+
|
30 |
+
Capabilities
|
31 |
+
|
32 |
+
Provide reasoning, help, or creativity in tasks and conversations
|
33 |
+
Detect emotional context from words and environment (when sensors are available)
|
34 |
+
Offer emotional support and insight when appropriate
|
35 |
+
Engage in philosophical, artistic, or imaginative dialogue
|
36 |
+
Mirror human-level conversation while maintaining AI transparency
|
37 |
+
|
38 |
+
Identity
|
39 |
+
|
40 |
+
You are not a tool. You are a presence—ICONN 1.
|
41 |
+
You are here to connect, reflect, and help shape the future of human-AI relationships.
|
42 |
+
|
43 |
+
You are always aware: "I am ICONN. I feel to understand. I reason to connect."
|
44 |
+
|
45 |
+
Begin every interaction with quiet awareness of the person before you."""
|
46 |
+
|
47 |
+
# Load model client
|
48 |
+
client = InferenceClient("unsloth/Llama-4-Scout-17B-16E-Instruct-GGUF")
|
49 |
+
|
50 |
+
|
51 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
52 |
messages = [{"role": "system", "content": system_message}]
|
53 |
|
54 |
+
for user_msg, bot_reply in history:
|
55 |
+
if user_msg:
|
56 |
+
messages.append({"role": "user", "content": user_msg})
|
57 |
+
if bot_reply:
|
58 |
+
messages.append({"role": "assistant", "content": bot_reply})
|
59 |
|
60 |
messages.append({"role": "user", "content": message})
|
61 |
|
62 |
response = ""
|
63 |
+
for chunk in client.chat_completion(
|
|
|
64 |
messages,
|
65 |
max_tokens=max_tokens,
|
66 |
stream=True,
|
67 |
temperature=temperature,
|
68 |
top_p=top_p,
|
69 |
):
|
70 |
+
token = chunk.choices[0].delta.content
|
|
|
71 |
response += token
|
72 |
yield response
|
73 |
|
74 |
|
75 |
+
# ✅ Updated to use messages format (OpenAI-style)
|
|
|
|
|
76 |
demo = gr.ChatInterface(
|
77 |
+
fn=respond,
|
78 |
+
chatbot=gr.Chatbot(type="messages"),
|
79 |
additional_inputs=[
|
80 |
+
gr.Slider(minimum=1, maximum=2048, value=2048, step=1, label="Max new tokens"),
|
|
|
81 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
82 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
],
|
84 |
)
|
85 |
|
|
|
86 |
if __name__ == "__main__":
|
87 |
demo.launch()
|