Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
|
| 2 |
import os
|
| 3 |
import gradio as gr
|
| 4 |
|
|
@@ -67,205 +67,6 @@ interface = gr.ChatInterface(
|
|
| 67 |
)
|
| 68 |
|
| 69 |
if __name__ == "__main__":
|
| 70 |
-
interface.launch(server_name="0.0.0.0", server_port=7860)
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
import requests
|
| 74 |
-
import os
|
| 75 |
-
import gradio as gr
|
| 76 |
-
|
| 77 |
-
API_TOKEN = os.getenv("HF_API_TOKEN")
|
| 78 |
-
if not API_TOKEN:
|
| 79 |
-
raise ValueError("HF_API_TOKEN not found. Please set it in the Space Secrets.")
|
| 80 |
-
|
| 81 |
-
MODEL_URL = "https://api-inference.huggingface.co/models/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B"
|
| 82 |
-
|
| 83 |
-
HEADERS = {
|
| 84 |
-
"Authorization": f"Bearer {API_TOKEN}",
|
| 85 |
-
"Content-Type": "application/json"
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
def query_deepseek(prompt):
|
| 89 |
-
"""Send a prompt to DeepSeek-R1 and get a response."""
|
| 90 |
-
english_prompt = f"Respond in English: {prompt}" # Force English response
|
| 91 |
-
payload = {
|
| 92 |
-
"inputs": english_prompt,
|
| 93 |
-
"parameters": {
|
| 94 |
-
"max_new_tokens": 150,
|
| 95 |
-
"temperature": 0.7,
|
| 96 |
-
"top_p": 0.85,
|
| 97 |
-
"repetition_penalty": 1.3,
|
| 98 |
-
"do_sample": True
|
| 99 |
-
}
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
try:
|
| 103 |
-
response = requests.post(MODEL_URL, headers=HEADERS, json=payload)
|
| 104 |
-
response.raise_for_status()
|
| 105 |
-
result = response.json()
|
| 106 |
-
return result[0]["generated_text"].split("Assistant:")[-1].strip()
|
| 107 |
-
except Exception as e:
|
| 108 |
-
return f"Error: {str(e)}"
|
| 109 |
-
|
| 110 |
-
def chat_interface(user_input, history):
|
| 111 |
-
"""Handle chatbot interaction with Gradio."""
|
| 112 |
-
response = query_deepseek(user_input)
|
| 113 |
-
return response
|
| 114 |
-
|
| 115 |
-
cyberpunk_css = """
|
| 116 |
-
@keyframes matrix {
|
| 117 |
-
0% { background-position: 0% 0%; }
|
| 118 |
-
100% { background-position: 100% 100%; }
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
-
@keyframes glitch {
|
| 122 |
-
2% { transform: translate(2px, 0) skew(0deg); }
|
| 123 |
-
4% { transform: translate(-2px, 0) skew(0deg); }
|
| 124 |
-
96% { transform: translate(0, 0) skew(0deg); }
|
| 125 |
-
}
|
| 126 |
-
|
| 127 |
-
body {
|
| 128 |
-
background: #0a0a14;
|
| 129 |
-
color: #00ff9d;
|
| 130 |
-
font-family: 'Courier New', monospace;
|
| 131 |
-
overflow-x: hidden;
|
| 132 |
-
}
|
| 133 |
-
|
| 134 |
-
.gradio-container {
|
| 135 |
-
background: radial-gradient(circle at center, #1a1a2e 0%, #0a0a14 100%);
|
| 136 |
-
}
|
| 137 |
-
|
| 138 |
-
.gr-chat-interface {
|
| 139 |
-
background: rgba(10, 10, 20, 0.95) !important;
|
| 140 |
-
border: 1px solid #4d00ff !important;
|
| 141 |
-
border-radius: 10px;
|
| 142 |
-
box-shadow: 0 0 20px #4d00ff33,
|
| 143 |
-
0 0 40px #4d00ff33,
|
| 144 |
-
inset 0 0 15px #4d00ff33;
|
| 145 |
-
position: relative;
|
| 146 |
-
overflow: hidden;
|
| 147 |
-
}
|
| 148 |
-
|
| 149 |
-
.gr-chat-interface::before {
|
| 150 |
-
content: '';
|
| 151 |
-
position: absolute;
|
| 152 |
-
top: -50%;
|
| 153 |
-
left: -50%;
|
| 154 |
-
width: 200%;
|
| 155 |
-
height: 200%;
|
| 156 |
-
background: linear-gradient(45deg,
|
| 157 |
-
transparent 45%,
|
| 158 |
-
#4d00ff 50%,
|
| 159 |
-
transparent 55%);
|
| 160 |
-
animation: matrix 20s linear infinite;
|
| 161 |
-
opacity: 0.1;
|
| 162 |
-
}
|
| 163 |
-
|
| 164 |
-
.chatbot {
|
| 165 |
-
background: rgba(0, 0, 0, 0.3) !important;
|
| 166 |
-
border: 1px solid #00ff9d33 !important;
|
| 167 |
-
border-radius: 8px;
|
| 168 |
-
margin: 15px;
|
| 169 |
-
height: 60vh;
|
| 170 |
-
}
|
| 171 |
-
|
| 172 |
-
.message {
|
| 173 |
-
padding: 15px;
|
| 174 |
-
margin: 10px;
|
| 175 |
-
border-radius: 5px;
|
| 176 |
-
position: relative;
|
| 177 |
-
background: rgba(0, 255, 157, 0.05) !important;
|
| 178 |
-
border: 1px solid #00ff9d33 !important;
|
| 179 |
-
backdrop-filter: blur(5px);
|
| 180 |
-
animation: glitch 5s infinite;
|
| 181 |
-
}
|
| 182 |
-
|
| 183 |
-
.user-message {
|
| 184 |
-
border-left: 3px solid #4d00ff !important;
|
| 185 |
-
margin-left: 30px;
|
| 186 |
-
}
|
| 187 |
-
|
| 188 |
-
.bot-message {
|
| 189 |
-
border-right: 3px solid #00ff9d !important;
|
| 190 |
-
margin-right: 30px;
|
| 191 |
-
}
|
| 192 |
-
|
| 193 |
-
input[type="text"] {
|
| 194 |
-
background: rgba(0, 0, 0, 0.5) !important;
|
| 195 |
-
border: 1px solid #4d00ff !important;
|
| 196 |
-
color: #00ff9d !important;
|
| 197 |
-
padding: 12px !important;
|
| 198 |
-
font-family: 'Courier New' !important;
|
| 199 |
-
border-radius: 5px !important;
|
| 200 |
-
box-shadow: 0 0 10px #4d00ff33 !important;
|
| 201 |
-
}
|
| 202 |
|
| 203 |
-
#submit_btn {
|
| 204 |
-
background: linear-gradient(45deg, #4d00ff, #00ff9d) !important;
|
| 205 |
-
color: #000 !important;
|
| 206 |
-
border: none !important;
|
| 207 |
-
padding: 12px 25px !important;
|
| 208 |
-
border-radius: 5px !important;
|
| 209 |
-
font-weight: bold !important;
|
| 210 |
-
text-transform: uppercase !important;
|
| 211 |
-
letter-spacing: 2px !important;
|
| 212 |
-
transition: 0.3s !important;
|
| 213 |
-
}
|
| 214 |
|
| 215 |
-
#submit_btn:hover {
|
| 216 |
-
box-shadow: 0 0 20px #00ff9d66 !important;
|
| 217 |
-
transform: scale(1.05) !important;
|
| 218 |
-
}
|
| 219 |
-
|
| 220 |
-
.title {
|
| 221 |
-
font-size: 2.5em;
|
| 222 |
-
text-align: center;
|
| 223 |
-
text-shadow: 0 0 10px #00ff9d;
|
| 224 |
-
animation: glitch 5s infinite;
|
| 225 |
-
position: relative;
|
| 226 |
-
}
|
| 227 |
-
|
| 228 |
-
.description {
|
| 229 |
-
color: #4d00ff;
|
| 230 |
-
text-align: center;
|
| 231 |
-
font-size: 1.2em;
|
| 232 |
-
margin-bottom: 2em;
|
| 233 |
-
}
|
| 234 |
-
|
| 235 |
-
::-webkit-scrollbar {
|
| 236 |
-
width: 8px;
|
| 237 |
-
}
|
| 238 |
-
|
| 239 |
-
::-webkit-scrollbar-thumb {
|
| 240 |
-
background: linear-gradient(#4d00ff, #00ff9d);
|
| 241 |
-
border-radius: 4px;
|
| 242 |
-
}
|
| 243 |
-
|
| 244 |
-
@keyframes terminal-blink {
|
| 245 |
-
0% { opacity: 1; }
|
| 246 |
-
50% { opacity: 0; }
|
| 247 |
-
100% { opacity: 1; }
|
| 248 |
-
}
|
| 249 |
-
|
| 250 |
-
.message::after {
|
| 251 |
-
content: '|';
|
| 252 |
-
animation: terminal-blink 1s infinite;
|
| 253 |
-
color: #00ff9d;
|
| 254 |
-
position: absolute;
|
| 255 |
-
right: 10px;
|
| 256 |
-
}
|
| 257 |
-
"""
|
| 258 |
-
|
| 259 |
-
interface = gr.ChatInterface(
|
| 260 |
-
fn=chat_interface,
|
| 261 |
-
title="⚡ CYBER-CHAT 3000 ⚡",
|
| 262 |
-
description="> ENGLISH-ONLY NEURAL INTERFACE // v1.3.37",
|
| 263 |
-
theme=gr.themes.Default(
|
| 264 |
-
primary_hue="cyan",
|
| 265 |
-
secondary_hue="purple"
|
| 266 |
-
),
|
| 267 |
-
css=cyberpunk_css
|
| 268 |
-
)
|
| 269 |
-
|
| 270 |
-
if __name__ == "__main__":
|
| 271 |
-
interface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
+
import requests
|
| 2 |
import os
|
| 3 |
import gradio as gr
|
| 4 |
|
|
|
|
| 67 |
)
|
| 68 |
|
| 69 |
if __name__ == "__main__":
|
| 70 |
+
interface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|