lamgamepro1 commited on
Commit
4f31805
·
verified ·
1 Parent(s): 652dac9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -38
app.py CHANGED
@@ -4,35 +4,36 @@ import os
4
 
5
  HF_TOKEN = os.getenv("HUGGINGFACE_HUB_TOKEN")
6
 
7
- def pure_ai_chat(message):
8
- """AI THẬT 100% - KHÔNG FALLBACK"""
9
  client = InferenceClient(token=HF_TOKEN)
10
 
11
- # DÙNG MODEL TỐT NHẤT + PROMPT HAY
12
- prompt = f"""Hãy trả lời câu hỏi tiếng Việt một cách tự nhiên:
13
-
14
- User: {message}
15
- Assistant:"""
16
-
17
- result = client.text_generation(
18
- prompt,
19
- model="google-t5/t5-base", # Model mạnh hơn
20
- max_new_tokens=120,
21
- temperature=0.9,
22
- do_sample=True,
23
- repetition_penalty=1.1
24
- )
25
-
26
- # Trích xuất response sạch
27
- response = result[0].generated_text[len(prompt):].strip()
28
- return response if response else "NodeAI: Tôi đã nhận câu hỏi của bạn."
 
29
 
30
  def respond(message, history):
31
  """FORMAT GRADIO 6.9.0"""
32
  if not message.strip():
33
  return "", history
34
 
35
- reply = pure_ai_chat(message)
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
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
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 100% • T5-base • No Mock</p>
51
  </div>
52
  """)
53
 
54
  with gr.Row():
55
- with gr.Column(scale=1, min_width=300):
56
- gr.Markdown("### AI Engine")
57
- gr.Markdown("**Model:** `google-t5/t5-base`")
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, show_label=False)
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(primary_hue="blue"),
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
  )