freddyaboulton HF Staff commited on
Commit
592026b
·
verified ·
1 Parent(s): 2bbb5d2

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +7 -7
  2. requirements.txt +2 -0
  3. run.ipynb +1 -0
  4. run.py +44 -0
README.md CHANGED
@@ -1,12 +1,12 @@
 
1
  ---
2
- title: Chatinterface Artifacts Main
3
- emoji: 🦀
4
- colorFrom: blue
5
- colorTo: purple
6
  sdk: gradio
7
  sdk_version: 5.7.1
8
- app_file: app.py
9
  pinned: false
 
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+
2
  ---
3
+ title: chatinterface_artifacts_main
4
+ emoji: 🔥
5
+ colorFrom: indigo
6
+ colorTo: indigo
7
  sdk: gradio
8
  sdk_version: 5.7.1
9
+ app_file: run.py
10
  pinned: false
11
+ hf_oauth: true
12
  ---
 
 
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio-client @ git+https://github.com/gradio-app/gradio@01b919f04b69732fd8adb52f6d156e5683589221#subdirectory=client/python
2
+ https://gradio-pypi-previews.s3.amazonaws.com/01b919f04b69732fd8adb52f6d156e5683589221/gradio-5.7.1-py3-none-any.whl
run.ipynb ADDED
@@ -0,0 +1 @@
 
 
1
+ {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: chatinterface_artifacts"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "\n", "python_code = \"\"\"\n", "def fib(n):\n", " if n <= 0:\n", " return 0\n", " elif n == 1:\n", " return 1\n", " else:\n", " return fib(n-1) + fib(n-2)\n", "\"\"\"\n", "\n", "js_code = \"\"\"\n", "function fib(n) {\n", " if (n <= 0) return 0;\n", " if (n === 1) return 1;\n", " return fib(n - 1) + fib(n - 2);\n", "}\n", "\"\"\"\n", "\n", "def chat(message, history):\n", " if \"python\" in message.lower():\n", " return \"Type Python or JavaScript to see the code.\", gr.Code(language=\"python\", value=python_code)\n", " elif \"javascript\" in message.lower():\n", " return \"Type Python or JavaScript to see the code.\", gr.Code(language=\"javascript\", value=js_code)\n", " else:\n", " return \"Please ask about Python or JavaScript.\", None\n", "\n", "with gr.Blocks() as demo:\n", " code = gr.Code(render=False)\n", " with gr.Row():\n", " with gr.Column():\n", " gr.Markdown(\"<center><h1>Write Python or JavaScript</h1></center>\")\n", " gr.ChatInterface(\n", " chat,\n", " examples=[\"Python\", \"JavaScript\"],\n", " additional_outputs=[code],\n", " type=\"messages\"\n", " )\n", " with gr.Column():\n", " gr.Markdown(\"<center><h1>Code Artifacts</h1></center>\")\n", " code.render()\n", "\n", "demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ python_code = """
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 "python" in message.lower():
23
+ return "Type Python or JavaScript to see the code.", gr.Code(language="python", value=python_code)
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=["Python", "JavaScript"],
37
+ additional_outputs=[code],
38
+ type="messages"
39
+ )
40
+ with gr.Column():
41
+ gr.Markdown("<center><h1>Code Artifacts</h1></center>")
42
+ code.render()
43
+
44
+ demo.launch()