Spaces:
Running
Running
Commit
·
d89074f
1
Parent(s):
d8d3eef
Test
Browse files
app.py
CHANGED
@@ -1,44 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
4 |
-
def fib(n):
|
5 |
-
if n <= 0:
|
6 |
-
return 0
|
7 |
-
elif n == 1:
|
8 |
-
return 1
|
9 |
-
else:
|
10 |
-
return fib(n-1) + fib(n-2)
|
11 |
-
"""
|
12 |
|
13 |
-
js_code = """
|
14 |
-
function fib(n) {
|
15 |
-
if (n <= 0) return 0;
|
16 |
-
if (n === 1) return 1;
|
17 |
-
return fib(n - 1) + fib(n - 2);
|
18 |
-
}
|
19 |
-
"""
|
20 |
|
21 |
def chat(message, history):
|
22 |
-
if "
|
23 |
-
return "Type Python or JavaScript to see the code.", gr.Code(language="
|
24 |
-
elif "javascript" in message.lower():
|
25 |
-
return "Type Python or JavaScript to see the code.", gr.Code(language="javascript", value=js_code)
|
26 |
else:
|
27 |
return "Please ask about Python or JavaScript.", None
|
28 |
|
29 |
with gr.Blocks() as demo:
|
30 |
code = gr.Code(render=False)
|
31 |
with gr.Row():
|
32 |
-
with gr.Column():
|
33 |
gr.Markdown("<center><h1>Write Python or JavaScript</h1></center>")
|
34 |
gr.ChatInterface(
|
35 |
chat,
|
36 |
-
examples=["
|
37 |
additional_outputs=[code],
|
38 |
type="messages"
|
39 |
)
|
40 |
-
|
41 |
-
gr.Markdown("<center><h1>Code Artifacts</h1></center>")
|
42 |
code.render()
|
43 |
|
44 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
json_code = "```json\n{\n \"classes\": [\n \"http://data.europa.eu/949/ContactLineSystem\"\n ],\n \"properties\": [\n \"http://data.europa.eu/949/contactLineSystemType\",\n \"http://data.europa.eu/949/energySupplySystemTSICompliant\",\n \"http://data.europa.eu/949/conditionsAppliedRegenerativeBraking\",\n \"http://data.europa.eu/949/conditionalRegenerativeBrake\"\n ]\n}\n```"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
def chat(message, history):
|
7 |
+
if "test" in message.lower():
|
8 |
+
return "Type Python or JavaScript to see the code.", gr.Code(language="json", value=json_code)
|
|
|
|
|
9 |
else:
|
10 |
return "Please ask about Python or JavaScript.", None
|
11 |
|
12 |
with gr.Blocks() as demo:
|
13 |
code = gr.Code(render=False)
|
14 |
with gr.Row():
|
|
|
15 |
gr.Markdown("<center><h1>Write Python or JavaScript</h1></center>")
|
16 |
gr.ChatInterface(
|
17 |
chat,
|
18 |
+
examples=["Test"],
|
19 |
additional_outputs=[code],
|
20 |
type="messages"
|
21 |
)
|
22 |
+
with gr.Row():
|
|
|
23 |
code.render()
|
24 |
|
25 |
demo.launch()
|