Rayso / app.py
rayochoajr's picture
Update app.py
b508f76
raw
history blame
1.62 kB
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()