Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import uuid
|
4 |
+
|
5 |
+
# Function to send POST request
|
6 |
+
def send_post_request(prompt, ratio, style):
|
7 |
+
# Define the URL
|
8 |
+
url = "https://ai.hardstonepte.ltd/ai/art/txt2img/"
|
9 |
+
|
10 |
+
# Define the headers with the required values
|
11 |
+
headers = {
|
12 |
+
"Uid": str(uuid.uuid4()), # Generating a new UUID
|
13 |
+
"Versioncode": "16701",
|
14 |
+
"Accept-Version": "v1",
|
15 |
+
"Token": "your_token_here", # Replace with the actual token
|
16 |
+
"Content-Type": "application/x-www-form-urlencoded"
|
17 |
+
}
|
18 |
+
|
19 |
+
# Define the values to be sent in the POST request
|
20 |
+
data = {
|
21 |
+
"is_translate": "1",
|
22 |
+
"is_first": "true",
|
23 |
+
"prompt": prompt,
|
24 |
+
"ratio": ratio,
|
25 |
+
"style_id": style
|
26 |
+
}
|
27 |
+
|
28 |
+
# Sending POST request
|
29 |
+
response = requests.post(url, headers=headers, data=data)
|
30 |
+
|
31 |
+
# Return the response text or any relevant information
|
32 |
+
if response.status_code == 200:
|
33 |
+
return response.text
|
34 |
+
else:
|
35 |
+
return f"Error: {response.status_code} - {response.text}"
|
36 |
+
|
37 |
+
# Gradio interface
|
38 |
+
def create_interface():
|
39 |
+
# Create the Gradio interface with inputs for prompt, ratio, and style
|
40 |
+
interface = gr.Interface(
|
41 |
+
fn=send_post_request,
|
42 |
+
inputs=[
|
43 |
+
gr.Textbox(label="Prompt"),
|
44 |
+
gr.Textbox(label="Ratio"),
|
45 |
+
gr.Textbox(label="Style ID")
|
46 |
+
],
|
47 |
+
outputs="text", # Output the raw response text from the POST request
|
48 |
+
title="POST Request to AI Service",
|
49 |
+
description="Send a POST request to the AI service with specified parameters"
|
50 |
+
)
|
51 |
+
return interface
|
52 |
+
|
53 |
+
# Launch the Gradio interface
|
54 |
+
interface = create_interface()
|
55 |
+
interface.launch()
|