Anil commited on
Commit
f3db210
·
1 Parent(s): 7cbe718

modified form

Browse files
Files changed (1) hide show
  1. app.py +40 -15
app.py CHANGED
@@ -1,19 +1,45 @@
1
  import gradio as gr
2
  import requests # For making the API call to the Lambda function
 
3
 
4
- def process_email(email, password):
5
- print(email)
6
- print(password)
7
- # This is where you'd put your actual Lambda function endpoint
8
- lambda_endpoint = 'https://your-lambdaa-function-url'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- # Preparing the payload to send; ensure this matches what your Lambda function expects
11
  payload = {
12
- "email": email,
13
  "password": password
14
  }
15
 
16
- # Making the POST request to the Lambda function
17
  try:
18
  response = requests.post(lambda_endpoint, json=payload)
19
  response_data = response.json()
@@ -22,19 +48,18 @@ def process_email(email, password):
22
  else:
23
  return f"Error: {response_data.get('message', 'No message returned.')}"
24
  except Exception as e:
25
- return f"Failed to call Lambda function: {str(e)}"
26
 
27
  iface = gr.Interface(
28
- process_email,
29
  inputs=[
30
- gr.Textbox(label="Enter Email"),
31
  gr.Textbox(label="Enter Password", type="password")
32
  ],
33
  outputs="textbox",
34
  live=False,
35
- title="Email Processing Demo 1",
36
- description="Enter an email address and password for processing.",
37
  )
38
 
39
- # Add an Export button to the Textbox output
40
- iface.launch(share=True)
 
1
  import gradio as gr
2
  import requests # For making the API call to the Lambda function
3
+ import re # For regular expression pattern matching
4
 
5
+ # Regular expression for domain validation
6
+ domain_regex = r'^(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,6}$'
7
+
8
+ def validate_domain(domain):
9
+ """Validate the domain format using regular expression."""
10
+ # Strip off the protocol if it's there
11
+ if domain.startswith("http://"):
12
+ domain = domain[7:]
13
+ elif domain.startswith("https://"):
14
+ domain = domain[8:]
15
+ elif domain.startswith("www."):
16
+ domain = domain[4:]
17
+
18
+ # Now validate the domain
19
+ if re.match(domain_regex, domain):
20
+ return True
21
+ else:
22
+ return False
23
+
24
+ def process_lead_search(domain, password):
25
+ # Validate the domain
26
+
27
+ if not validate_domain(domain):
28
+ return "Error: The domain format is invalid. Please enter a valid domain."
29
+
30
+ # Check if the password is not empty
31
+ if not password:
32
+ return "Error: The password cannot be empty."
33
+
34
+ lambda_endpoint = 'https://beta.nextbee.com/lib/scripts/replication_logs/index.php?db=jtaxbeta'
35
 
36
+ # Prepare the payload to send; ensure this matches what your Lambda function expects
37
  payload = {
38
+ "domain": domain,
39
  "password": password
40
  }
41
 
42
+ # Make the POST request to the Lambda function
43
  try:
44
  response = requests.post(lambda_endpoint, json=payload)
45
  response_data = response.json()
 
48
  else:
49
  return f"Error: {response_data.get('message', 'No message returned.')}"
50
  except Exception as e:
51
+ return f"Failed to call API : {str(e)}"
52
 
53
  iface = gr.Interface(
54
+ process_lead_search,
55
  inputs=[
56
+ gr.Textbox(label="Enter Domain"),
57
  gr.Textbox(label="Enter Password", type="password")
58
  ],
59
  outputs="textbox",
60
  live=False,
61
+ title="Lead Search",
62
+ description="Enter domain and password for processing.",
63
  )
64
 
65
+ iface.launch(share=True)