Offex commited on
Commit
833fee3
·
verified ·
1 Parent(s): f07c81c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -34
app.py CHANGED
@@ -1,48 +1,50 @@
1
  import gradio as gr
2
  import requests
3
- import time
4
-
5
- BASE_URL = "https://www.1secmail.com/api/v1/"
6
 
7
  def generate_email():
8
- res = requests.get(f"{BASE_URL}?action=genAddrs&count=1")
9
- email = res.json()[0]
10
- return email
 
 
 
 
 
 
11
 
12
  def check_inbox(email_address):
13
  if not email_address or "@" not in email_address:
14
- return "कृपया पहले ईमेल जनरेट करें।"
15
-
16
- user, domain = email_address.split('@')
17
- check_url = f"{BASE_URL}?action=getMessages&login={user}&domain={domain}"
18
- messages = requests.get(check_url).json()
19
-
20
- if not messages:
21
- return "इनबॉक्स खाली है। (Refresh करें अगर अभी मेल भेजा है)"
22
 
23
- output = ""
24
- for msg in messages:
25
- msg_id = msg['id']
26
- content_url = f"{BASE_URL}?action=readMessage&login={user}&domain={domain}&id={msg_id}"
27
- content = requests.get(content_url).json()
28
- output += f"--- NEW MESSAGE ---\nFrom: {content['from']}\nSubject: {content['subject']}\nDate: {content['date']}\n\nContent:\n{content['textBody']}\n\n"
29
-
30
- return output
 
 
 
 
 
 
 
 
 
31
 
32
- # UI डिज़ाइन
33
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
34
- gr.Markdown("# 📧 My Private Temp Mail Tool")
35
- gr.Markdown("बिना किसी API Key के अपना खुद का ईमेल टूल इस्तेमाल करें।")
36
-
37
  with gr.Row():
38
- email_display = gr.Textbox(label="आपका अस्थाई ईमेल", placeholder="यहाँ ईमेल आएगा...", interactive=False)
39
- gen_btn = gr.Button("🆕 नया ईमेल बनाएँ")
40
 
41
- with gr.Column():
42
- inbox_display = gr.TextArea(label="📥 इनबॉक्स (Messages)", interactive=False, lines=10)
43
- refresh_btn = gr.Button("🔄 मैसेज चेक करें")
44
 
45
- gen_btn.click(generate_email, outputs=email_display)
46
- refresh_btn.click(check_inbox, inputs=email_display, outputs=inbox_display)
47
 
48
  demo.launch()
 
1
  import gradio as gr
2
  import requests
 
 
 
3
 
4
  def generate_email():
5
+ try:
6
+ # 1secmail की फ्री API
7
+ response = requests.get("https://www.1secmail.com/api/v1/?action=genAddrs&count=1", timeout=10)
8
+ if response.status_code == 200:
9
+ return response.json()[0]
10
+ else:
11
+ return f"Error: API status {response.status_code}"
12
+ except Exception as e:
13
+ return f"Connection Error: {str(e)}"
14
 
15
  def check_inbox(email_address):
16
  if not email_address or "@" not in email_address:
17
+ return "पहले ईमेल जनरेट करें!"
 
 
 
 
 
 
 
18
 
19
+ try:
20
+ user, domain = email_address.split('@')
21
+ url = f"https://www.1secmail.com/api/v1/?action=getMessages&login={user}&domain={domain}"
22
+ messages = requests.get(url, timeout=10).json()
23
+
24
+ if not messages:
25
+ return "इनबॉक्स खाली है। कृपया इंतज़ार करें..."
26
+
27
+ result = ""
28
+ for m in messages:
29
+ msg_id = m['id']
30
+ # मैसेज की पूरी डिटेल लेना
31
+ full_msg = requests.get(f"https://www.1secmail.com/api/v1/?action=readMessage&login={user}&domain={domain}&id={msg_id}").json()
32
+ result += f"From: {full_msg['from']}\nSubject: {full_msg['subject']}\n---\n{full_msg['textBody']}\n\n"
33
+ return result
34
+ except Exception as e:
35
+ return f"Error fetching mail: {str(e)}"
36
 
37
+ # UI Layout
38
+ with gr.Blocks() as demo:
39
+ gr.Markdown("# 📧 My Private Temp Mail")
 
 
40
  with gr.Row():
41
+ email_box = gr.Textbox(label="आपका ईमेल", interactive=False)
42
+ gen_btn = gr.Button("Generate Email")
43
 
44
+ inbox_area = gr.TextArea(label="Inbox", interactive=False)
45
+ refresh_btn = gr.Button("Check Inbox")
 
46
 
47
+ gen_btn.click(generate_email, outputs=email_box)
48
+ refresh_btn.click(check_inbox, inputs=email_box, outputs=inbox_area)
49
 
50
  demo.launch()