testnow720's picture
Update app.py
ca95771 verified
raw
history blame
1.02 kB
import gradio as gr
import requests
def execute(code_snippet, lang):
lang_param = None
match lang:
case "C++": lang_param = "cpp"
case "C#": lang_param = "cs"
case _: lang_param = lang.lower()
res = requests.request("POST", f"https://try.w3schools.com/try_{lang_param}.php", data={
"code": code_snippet
})
return res.text
demo = gr.Interface(
fn=execute,
inputs=[
gr.Textbox(
show_label=True,
label="Code",
max_lines=4_294_967_295,
lines=4_294_967_295,
value="print('Hello, World!')",
),
gr.Dropdown(
show_label=True,
label="Language",
choices=["Python", "Java", "C", "C++", "C#", "PHP", "JavaScript"],
value="Python"
),
],
outputs=gr.Textbox(label="Result"),
title="HFChat Code Executor",
description="Enter the code snippet and language that you want to execute.",
)
demo.launch(debug=True)