hittu22 commited on
Commit
22b5afa
·
verified ·
1 Parent(s): 9ffb477

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -20
app.py CHANGED
@@ -1,39 +1,54 @@
1
  import os
2
  import pexpect
3
  import gradio as gr
 
4
 
5
- # 1. Background Automation Logic (Bitping Auto-Login)
6
  def init_bitping():
 
7
  email = os.environ.get("EMAIL")
8
  password = os.environ.get("PASSWORD")
9
 
10
- if email and password:
11
- try:
12
- # Login command
13
- child = pexpect.spawn('bitpingd login', encoding='utf-8', timeout=15)
14
- child.expect('Email:')
15
- child.sendline(email)
16
- child.expect('Password:')
17
- child.sendline(password)
18
- child.expect(pexpect.EOF)
19
-
20
- # Background run
21
- os.system("nohup bitpingd > /dev/null 2>&1 &")
22
- except Exception as e:
23
- print(f"Error: {e}")
24
 
25
- # Script run hote hi sabse pehle node start hoga
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  init_bitping()
27
 
28
- # 2. Fake Chatbot UI Logic (To trick Hugging Face)
29
  def chat_response(message, history):
30
- return "Thanks for your message! I am a simple support bot. Our team will get back to you shortly."
31
 
32
- # Theme parameter hata diya taaki Gradio error na de
33
  demo = gr.ChatInterface(
34
  fn=chat_response,
35
  title="Customer Support Chat",
36
- description="Simple web chat interface for customer queries."
37
  )
38
 
39
  if __name__ == "__main__":
 
1
  import os
2
  import pexpect
3
  import gradio as gr
4
+ import time
5
 
 
6
  def init_bitping():
7
+ # Hugging Face Settings -> Secrets se email/password uthayega
8
  email = os.environ.get("EMAIL")
9
  password = os.environ.get("PASSWORD")
10
 
11
+ if not email or not password:
12
+ print("❌ Secret keys (EMAIL / PASSWORD) nahi mile! Please HF Settings me check karein.")
13
+ return
 
 
 
 
 
 
 
 
 
 
 
14
 
15
+ try:
16
+ print("⏳ Bitping me auto-login process start ho raha hai...")
17
+
18
+ # Bitping ka direct (full) path use kar rahe hain taaki error na aaye
19
+ bitping_path = "/root/.bitping/bin/bitpingd"
20
+
21
+ # Login Process
22
+ child = pexpect.spawn(f'{bitping_path} login', encoding='utf-8', timeout=15)
23
+
24
+ child.expect('(?i)email') # 'Email:' prompt ka wait karega
25
+ child.sendline(email)
26
+
27
+ child.expect('(?i)password') # 'Password:' prompt ka wait karega
28
+ child.sendline(password)
29
+
30
+ # Password daalne ke baad login server par register hone ke liye 5 second rukega
31
+ time.sleep(5)
32
+ print("✅ Login successful!")
33
+
34
+ # Node ko safely background me run karega
35
+ os.system(f"nohup {bitping_path} > /root/bitping_run.log 2>&1 &")
36
+ print("🚀 Bitping Node background me start ho gaya hai!")
37
+
38
+ except Exception as e:
39
+ print(f"❌ Background error: {e}")
40
+
41
+ # Script load hote hi auto-login function chalega
42
  init_bitping()
43
 
44
+ # Fake Chat UI
45
  def chat_response(message, history):
46
+ return "Thanks for reaching out! I am a customer support bot. How can I help you today?"
47
 
 
48
  demo = gr.ChatInterface(
49
  fn=chat_response,
50
  title="Customer Support Chat",
51
+ description="Welcome to our support channel."
52
  )
53
 
54
  if __name__ == "__main__":