def process_input()

in use-cases/rag-pipeline/frontend/src/interface.py [0:0]


def process_input(text=None, image_uri=None):
    """
    Processes the input (text, image_uri or both) and sends a POST request to the backend.

    Args:
      text: The input text(optional).
      image_uri: The GCS URI of the image (optional).

    Returns:
      The response from the backend.
    """
    if text and not validate_text(text):
        return "Invalid text input provided."

    if image_uri and not validate_gcs_uri(image_uri):
        return "Invalid GCS URI provided."

    data = {}
    if text:
        data["text"] = text
    if image_uri:
        data["image_uri"] = image_uri

    if not data:  # Check if data is empty
        return "Please provide either text or image URI."

    response = requests.post(BACKEND_SERVICE_URL, json=data, timeout=100)

    response.raise_for_status()  # Raise an exception for bad status codes
    logger.info("Received response from backend service:%s", response.text)
    return response.json()