Update app.py
Browse files
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 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
# UI
|
| 33 |
-
with gr.Blocks(
|
| 34 |
-
gr.Markdown("# 📧 My Private Temp Mail
|
| 35 |
-
gr.Markdown("बिना किसी API Key के अपना खुद का ईमेल टूल इस्तेमाल करें।")
|
| 36 |
-
|
| 37 |
with gr.Row():
|
| 38 |
-
|
| 39 |
-
gen_btn = gr.Button("
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
refresh_btn = gr.Button("🔄 मैसेज चेक करें")
|
| 44 |
|
| 45 |
-
gen_btn.click(generate_email, outputs=
|
| 46 |
-
refresh_btn.click(check_inbox, inputs=
|
| 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()
|