import gradio as gr import requests import uuid # Function to send POST request def send_post_request(prompt, ratio, style): # Define the URL url = "https://ai.hardstonepte.ltd/ai/art/txt2img/" # Define the headers with the required values headers = { "Uid": str(uuid.uuid4()), # Generating a new UUID "Versioncode": "16701", "Accept-Version": "v1", "Token": "your_token_here", # Replace with the actual token "Content-Type": "application/x-www-form-urlencoded" } # Define the values to be sent in the POST request data = { "is_translate": "1", "is_first": "true", "prompt": prompt, "ratio": ratio, "style_id": style } # Sending POST request response = requests.post(url, headers=headers, data=data) # Return the response text or any relevant information if response.status_code == 200: return response.text else: return f"Error: {response.status_code} - {response.text}" # Gradio interface def create_interface(): # Create the Gradio interface with inputs for prompt, ratio, and style interface = gr.Interface( fn=send_post_request, inputs=[ gr.Textbox(label="Prompt"), gr.Textbox(label="Ratio"), gr.Textbox(label="Style ID") ], outputs="text", # Output the raw response text from the POST request title="POST Request to AI Service", description="Send a POST request to the AI service with specified parameters" ) return interface # Launch the Gradio interface interface = create_interface() interface.launch()