File size: 1,617 Bytes
f626979
 
 
b508f76
f626979
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b508f76
f626979
 
 
b508f76
 
f626979
 
 
 
b508f76
f626979
b508f76
 
 
 
f626979
 
b508f76
f626979
245110e
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
import gradio as gr
import requests

# Function to interact with the Rayso API
def get_code_screenshot(code, title, theme, background, darkMode, padding, language):
    payload = {
        "code": code,
        "title": title,
        "theme": theme,
        "background": background,
        "darkMode": darkMode,
        "padding": padding,
        "language": language
    }
    response = requests.post("https://rayso.herokuapp.com/api", json=payload)
    if response.status_code == 200:
        data = response.json()
        image_url = data.get('url')
        return image_url
    else:
        return f"Failed to get image: {response.status_code}"

# Gradio Interface
iface = gr.Interface(
    fn=get_code_screenshot,
    inputs=[
        gr.inputs.Textbox(lines=10, placeholder="Enter your code here...", label="Code"),
        gr.inputs.Textbox(default="Untitled-1", placeholder="Enter title...", label="Title"),
        gr.inputs.Dropdown(choices=["breeze", "candy", "crimson", "falcon", "meadow", "midnight", "raindrop", "sunset"], label="Theme"),
        gr.inputs.Checkbox(default=True, label="Background"),
        gr.inputs.Checkbox(default=True, label="Dark Mode"),
        gr.inputs.Dropdown(choices=["16", "32", "64", "128"], label="Padding"),
        gr.inputs.Textbox(default="auto", placeholder="Enter language...", label="Language"),
    ],
    outputs=[
        gr.outputs.Image(type="url", label="Generated Image"),
    ],
    live=False  # Set to False to only call the function when the submit button is pressed
)

# Launch the Gradio interface
if __name__ == "__main__":
    iface.launch()