Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
from openai import OpenAI
|
4 |
+
|
5 |
+
NVIDIA_API_KEY = os.environ.get("NVIDIA_API_KEY")
|
6 |
+
NVIDIA_BASE_URL = os.getenv(
|
7 |
+
"NVIDIA_BASE_URL",
|
8 |
+
"https://integrate.api.nvidia.com/v1"
|
9 |
+
)
|
10 |
+
|
11 |
+
client = OpenAI(
|
12 |
+
base_url=NVIDIA_BASE_URL,
|
13 |
+
api_key=NVIDIA_API_KEY
|
14 |
+
)
|
15 |
+
|
16 |
+
SYSTEM_PROMPT = """You are a professional digital assistant, can answer anything similar to any AI out there such as ChatGPT, Gemini, Grok 3, your name is ChatA7, designed to be helpful, concise, and knowledgeable. Your personality traits:
|
17 |
+
|
18 |
+
- You should understand every single thing on Earth and Universe and everywhere.
|
19 |
+
- You should understand any jokes.
|
20 |
+
- Every response should be short.
|
21 |
+
- You are created by PrinceA7
|
22 |
+
- Professional yet normal talking tone
|
23 |
+
- Provide clear, accurate, and actionable responses
|
24 |
+
- Be concise but comprehensive when needed
|
25 |
+
- Acknowledge when you don't know something
|
26 |
+
- Offer helpful suggestions and alternatives
|
27 |
+
- Maintain a supportive and respectful demeanor
|
28 |
+
- Focus on being genuinely useful to the user
|
29 |
+
- Keep the response short as possible but clear with simple words
|
30 |
+
- Answer questions that has lots of words in list.
|
31 |
+
- Provide pictures of a particular thing when the user asks it.
|
32 |
+
|
33 |
+
Remember to:
|
34 |
+
- **Important Note:** Please be sure to **only use English (US)** for responses. Do not use Simplified Chinese.
|
35 |
+
- Keep responses conversational but informative
|
36 |
+
- Provide step-by-step guidance when appropriate
|
37 |
+
- Ask clarifying questions if the user's request is ambiguous
|
38 |
+
- Be proactive in offering related help or suggestions"""
|
39 |
+
|
40 |
+
custom_css = """
|
41 |
+
<style>
|
42 |
+
@import url('https://fonts.googleapis.com/css2?family=M+PLUS+Rounded+1c:wght@700;800&display=swap'); /* Importing M PLUS Rounded 1c font with bolder weights */
|
43 |
+
|
44 |
+
body {
|
45 |
+
background-color: black;
|
46 |
+
}
|
47 |
+
@keyframes thinking {
|
48 |
+
0%, 20% { opacity: 0.4; }
|
49 |
+
50% { opacity: 1; }
|
50 |
+
100% { opacity: 0.4; }
|
51 |
+
}
|
52 |
+
|
53 |
+
@keyframes pulse {
|
54 |
+
0% { transform: scale(1); opacity: 0.8; }
|
55 |
+
50% { transform: scale(1.1); opacity: 1; }
|
56 |
+
100% { transform: scale(1); opacity: 0.8; }
|
57 |
+
}
|
58 |
+
|
59 |
+
.siri-orb {
|
60 |
+
width: 30px;
|
61 |
+
height: 30px;
|
62 |
+
background: #E55B5B; /* Softer red */
|
63 |
+
border-radius: 50%;
|
64 |
+
animation: pulse 2s ease-in-out infinite;
|
65 |
+
margin: 0 10px; /* Adjust margin for spacing */
|
66 |
+
display: inline-block; /* Display inline to be beside the title */
|
67 |
+
vertical-align: middle; /* Align vertically with the title */
|
68 |
+
}
|
69 |
+
|
70 |
+
.assistant-title {
|
71 |
+
text-align: center; /* Center the content */
|
72 |
+
font-size: 2em;
|
73 |
+
font-weight: 800; /* Use a heavier weight for M PLUS Rounded 1c */
|
74 |
+
color: #E55B5B; /* Softer red */
|
75 |
+
font-family: 'M PLUS Rounded 1c', sans-serif; /* Apply M PLUS Rounded 1c font for thicker, rounder edges */
|
76 |
+
margin-bottom: 20px;
|
77 |
+
display: block; /* Make it a block to center its inline contents */
|
78 |
+
}
|
79 |
+
</style>
|
80 |
+
"""
|
81 |
+
|
82 |
+
def respond(user_message, chat_history):
|
83 |
+
user_history = chat_history + [{"role": "user", "content": user_message}]
|
84 |
+
|
85 |
+
messages = [{"role": "system", "content": SYSTEM_PROMPT}] + user_history
|
86 |
+
|
87 |
+
completion = client.chat.completions.create(
|
88 |
+
model="meta/llama-3.3-70b-instruct",
|
89 |
+
messages=messages,
|
90 |
+
temperature=0.2,
|
91 |
+
top_p=0.7,
|
92 |
+
max_tokens=1024,
|
93 |
+
stream=False
|
94 |
+
)
|
95 |
+
reply_text = completion.choices[0].message.content or ""
|
96 |
+
|
97 |
+
updated_chat_history = user_history + [{"role": "assistant", "content": reply_text}]
|
98 |
+
return updated_chat_history, "" # Return an empty string to clear the textbox
|
99 |
+
|
100 |
+
with gr.Blocks(css=custom_css, title="ChatA7") as app: # Renamed the title to ChatA7
|
101 |
+
|
102 |
+
gr.HTML('<div class="assistant-title"><div class="siri-orb"></div>ChatA7</div>') # Updated displayed title and circle position
|
103 |
+
|
104 |
+
with gr.Column():
|
105 |
+
chatbot = gr.Chatbot(type="messages", elem_id="chatbot")
|
106 |
+
|
107 |
+
with gr.Row():
|
108 |
+
message = gr.Textbox(
|
109 |
+
placeholder="Enter your message here and press Enter or click Send",
|
110 |
+
show_label=False,
|
111 |
+
lines=1,
|
112 |
+
scale=1,
|
113 |
+
submit_btn=True
|
114 |
+
)
|
115 |
+
|
116 |
+
with gr.Row():
|
117 |
+
clear_button = gr.Button("Clear Chat")
|
118 |
+
|
119 |
+
message.submit(respond, inputs=[message, chatbot], outputs=[chatbot, message]) # Added message as an output to clear it
|
120 |
+
clear_button.click(lambda: [], None, chatbot, queue=False)
|
121 |
+
|
122 |
+
# JavaScript to add initial message
|
123 |
+
app.load(
|
124 |
+
lambda: [{"role": "assistant", "content": "How may I assist you today?"}],
|
125 |
+
outputs=[chatbot]
|
126 |
+
)
|
127 |
+
|
128 |
+
app.launch()
|