import gradio as gr import requests # For making the API call to the API function import re # For regular expression pattern matching # Regular expression for domain validation domain_regex = r'^(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,6}$' def validate_domain(domain): """Validate the domain format using regular expression.""" # Strip off the protocol if it's there if domain.startswith("http://"): domain = domain[7:] elif domain.startswith("https://"): domain = domain[8:] elif domain.startswith("www."): domain = domain[4:] # Now validate the domain if re.match(domain_regex, domain): return True else: return False def process_lead_search(domain, password): # Validate the domain if not validate_domain(domain): return "Error: The domain format is invalid. Please enter a valid domain." # Check if the password is not empty if not password: return "Error: The password cannot be empty." api_endpoint = 'https://betaapi.nextbee.io/llm/api/generate_lead' # Prepare the payload to send; ensure this matches what your API function expects payload = { "domain": domain, "password": password } # Make the POST request to the API function try: response = requests.post(api_endpoint, json=payload) response_data = response.json() if response.status_code == 200: return response_data else: return f"Error: {response_data.get('message', 'No message returned.')}" except Exception as e: return f"Failed to call API : {str(e)}" iface = gr.Interface( process_lead_search, inputs=[ gr.Textbox(label="Enter Domain"), gr.Textbox(label="Enter Password", type="password") ], outputs="textbox", live=False, title="Lead Search", description="Enter domain and password for processing.", ) iface.launch()