Spaces:
Build error
Build error
File size: 1,949 Bytes
e7b01e2 5bc60f8 f3db210 e7b01e2 f3db210 2498f46 e7b01e2 5bc60f8 e7b01e2 f3db210 e7b01e2 5bc60f8 e7b01e2 5bc60f8 e7b01e2 c592119 e7b01e2 f3db210 e7b01e2 f3db210 e7b01e2 f3db210 e7b01e2 87a4dee e7b01e2 f3db210 e7b01e2 892d9b3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | 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()
|