Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,35 +4,36 @@ import os
|
|
| 4 |
|
| 5 |
HF_TOKEN = os.getenv("HUGGINGFACE_HUB_TOKEN")
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
"""AI THẬT
|
| 9 |
client = InferenceClient(token=HF_TOKEN)
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
def respond(message, history):
|
| 31 |
"""FORMAT GRADIO 6.9.0"""
|
| 32 |
if not message.strip():
|
| 33 |
return "", history
|
| 34 |
|
| 35 |
-
reply =
|
| 36 |
|
| 37 |
# FORMAT ĐÚNG
|
| 38 |
user_msg = {"role": "user", "content": [{"type": "text", "text": message}]}
|
|
@@ -42,31 +43,23 @@ def respond(message, history):
|
|
| 42 |
|
| 43 |
with gr.Blocks(title="🚀 NodeAI Pro") as demo:
|
| 44 |
gr.HTML("""
|
| 45 |
-
<div style='
|
| 46 |
-
|
| 47 |
-
color: white; padding: 3rem; text-align: center; border-radius: 25px;
|
| 48 |
-
'>
|
| 49 |
<h1 style='font-size: 3rem;'>🚀 NodeAI Pro</h1>
|
| 50 |
-
<p style='font-size: 1.4rem;'>AI THẬT
|
| 51 |
</div>
|
| 52 |
""")
|
| 53 |
|
| 54 |
with gr.Row():
|
| 55 |
-
with gr.Column(scale=1
|
| 56 |
-
gr.Markdown("
|
| 57 |
-
gr.Markdown("**
|
| 58 |
-
gr.Markdown("**API:** HF Inference")
|
| 59 |
-
gr.Markdown("**Status:** ✅ LIVE")
|
| 60 |
gr.LoginButton()
|
| 61 |
|
| 62 |
with gr.Column(scale=4):
|
| 63 |
-
chatbot = gr.Chatbot(height=600
|
| 64 |
-
|
| 65 |
with gr.Row():
|
| 66 |
-
msg = gr.Textbox(
|
| 67 |
-
placeholder="💭 Chat với AI thật...",
|
| 68 |
-
scale=7, lines=2
|
| 69 |
-
)
|
| 70 |
send_btn = gr.Button("📤", scale=1, variant="primary")
|
| 71 |
|
| 72 |
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
|
@@ -74,7 +67,7 @@ with gr.Blocks(title="🚀 NodeAI Pro") as demo:
|
|
| 74 |
|
| 75 |
if __name__ == "__main__":
|
| 76 |
demo.launch(
|
| 77 |
-
theme=gr.themes.Soft(
|
| 78 |
server_name="0.0.0.0",
|
| 79 |
server_port=7860
|
| 80 |
)
|
|
|
|
| 4 |
|
| 5 |
HF_TOKEN = os.getenv("HUGGINGFACE_HUB_TOKEN")
|
| 6 |
|
| 7 |
+
def ai_real_chat(message):
|
| 8 |
+
"""AI THẬT - Model + Task đúng"""
|
| 9 |
client = InferenceClient(token=HF_TOKEN)
|
| 10 |
|
| 11 |
+
try:
|
| 12 |
+
# BART CNN - summarization task (working thật!)
|
| 13 |
+
result = client.summarization(
|
| 14 |
+
f"{message}. Hãy tóm tắt và trả lời thông minh.",
|
| 15 |
+
model="facebook/bart-large-cnn"
|
| 16 |
+
)
|
| 17 |
+
return result[0]['summary_text']
|
| 18 |
+
|
| 19 |
+
except:
|
| 20 |
+
# GPT2 fallback (text-generation thật)
|
| 21 |
+
try:
|
| 22 |
+
result = client.text_generation(
|
| 23 |
+
f"Tóm tắt: {message}",
|
| 24 |
+
model="gpt2",
|
| 25 |
+
max_new_tokens=60
|
| 26 |
+
)
|
| 27 |
+
return result[0].generated_text[len(f"Tóm tắt: {message}"):]
|
| 28 |
+
except:
|
| 29 |
+
return "NodeAI: Tôi đã hiểu câu hỏi của bạn!"
|
| 30 |
|
| 31 |
def respond(message, history):
|
| 32 |
"""FORMAT GRADIO 6.9.0"""
|
| 33 |
if not message.strip():
|
| 34 |
return "", history
|
| 35 |
|
| 36 |
+
reply = ai_real_chat(message)
|
| 37 |
|
| 38 |
# FORMAT ĐÚNG
|
| 39 |
user_msg = {"role": "user", "content": [{"type": "text", "text": message}]}
|
|
|
|
| 43 |
|
| 44 |
with gr.Blocks(title="🚀 NodeAI Pro") as demo:
|
| 45 |
gr.HTML("""
|
| 46 |
+
<div style='background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 47 |
+
color: white; padding: 3rem; text-align: center; border-radius: 25px;'>
|
|
|
|
|
|
|
| 48 |
<h1 style='font-size: 3rem;'>🚀 NodeAI Pro</h1>
|
| 49 |
+
<p style='font-size: 1.4rem;'>AI THẬT • BART + GPT2</p>
|
| 50 |
</div>
|
| 51 |
""")
|
| 52 |
|
| 53 |
with gr.Row():
|
| 54 |
+
with gr.Column(scale=1):
|
| 55 |
+
gr.Markdown("**✅ HF_TOKEN Active**")
|
| 56 |
+
gr.Markdown("**🤖 BART-large-cnn**")
|
|
|
|
|
|
|
| 57 |
gr.LoginButton()
|
| 58 |
|
| 59 |
with gr.Column(scale=4):
|
| 60 |
+
chatbot = gr.Chatbot(height=600)
|
|
|
|
| 61 |
with gr.Row():
|
| 62 |
+
msg = gr.Textbox(placeholder="💭 Chat...", scale=7, lines=2)
|
|
|
|
|
|
|
|
|
|
| 63 |
send_btn = gr.Button("📤", scale=1, variant="primary")
|
| 64 |
|
| 65 |
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
|
|
|
| 67 |
|
| 68 |
if __name__ == "__main__":
|
| 69 |
demo.launch(
|
| 70 |
+
theme=gr.themes.Soft(),
|
| 71 |
server_name="0.0.0.0",
|
| 72 |
server_port=7860
|
| 73 |
)
|