Spaces:
Running
Running
Commit
β’
312de82
1
Parent(s):
b9bda01
add example for gradio
Browse files
src/generateFiles.mts
CHANGED
@@ -2,10 +2,12 @@ import { HfInference } from '@huggingface/inference'
|
|
2 |
import { RepoFile } from './types.mts'
|
3 |
import { createLlamaPrompt } from './createLlamaPrompt.mts'
|
4 |
import { parseTutorial } from './parseTutorial.mts'
|
5 |
-
import {
|
|
|
6 |
import { getWebApp } from './getWebApp.mts'
|
7 |
import { getReactApp } from './getReactApp.mts'
|
8 |
-
import {
|
|
|
9 |
import { isReactAppPrompt } from './isReactAppPrompt.mts'
|
10 |
|
11 |
export const generateFiles = async (
|
@@ -18,8 +20,10 @@ export const generateFiles = async (
|
|
18 |
}
|
19 |
|
20 |
const { prefix, files, instructions } =
|
21 |
-
|
22 |
-
?
|
|
|
|
|
23 |
: isReactAppPrompt(prompt)
|
24 |
? getReactApp(prompt)
|
25 |
: getWebApp(prompt)
|
|
|
2 |
import { RepoFile } from './types.mts'
|
3 |
import { createLlamaPrompt } from './createLlamaPrompt.mts'
|
4 |
import { parseTutorial } from './parseTutorial.mts'
|
5 |
+
import { getGradioApp } from './getGradioApp.mts'
|
6 |
+
import { getStreamlitApp } from './getStreamlitApp.mts'
|
7 |
import { getWebApp } from './getWebApp.mts'
|
8 |
import { getReactApp } from './getReactApp.mts'
|
9 |
+
import { isStreamlitAppPrompt } from './isStreamlitAppPrompt.mts'
|
10 |
+
import { isPythonOrGradioAppPrompt } from './isPythonOrGradioAppPrompt.mts'
|
11 |
import { isReactAppPrompt } from './isReactAppPrompt.mts'
|
12 |
|
13 |
export const generateFiles = async (
|
|
|
20 |
}
|
21 |
|
22 |
const { prefix, files, instructions } =
|
23 |
+
isStreamlitAppPrompt(prompt)
|
24 |
+
? getStreamlitApp(prompt)
|
25 |
+
: isPythonOrGradioAppPrompt(prompt)
|
26 |
+
? getGradioApp(prompt)
|
27 |
: isReactAppPrompt(prompt)
|
28 |
? getReactApp(prompt)
|
29 |
: getWebApp(prompt)
|
src/getGradioApp.mts
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { streamlitDoc } from "./streamlitDoc.mts";
|
2 |
+
|
3 |
+
export function getGradioApp(prompt: string) {
|
4 |
+
const prefix = "# In app.py:\n```"
|
5 |
+
|
6 |
+
const instructions = [
|
7 |
+
{
|
8 |
+
role: "system",
|
9 |
+
content: [
|
10 |
+
`You are a Python developer, expert at crafting Gradio applications to deploy to Hugging Face.`,
|
11 |
+
`Here is an example of a minimal Gradio application:`,
|
12 |
+
streamlitDoc
|
13 |
+
].filter(item => item).join("\n")
|
14 |
+
},
|
15 |
+
{
|
16 |
+
role: "user",
|
17 |
+
content: `Please write, file by file, the source code for a Gradio project.
|
18 |
+
|
19 |
+
You are allowed to use (if necessary) the following Python modules:
|
20 |
+
- numpy
|
21 |
+
- gradio (version 3.39.0)
|
22 |
+
- matplotlib
|
23 |
+
|
24 |
+
Don't forget to write a README.md with the following header:
|
25 |
+
\`\`\`
|
26 |
+
---
|
27 |
+
license: apache-2.0
|
28 |
+
title: <app name>
|
29 |
+
sdk: gradio
|
30 |
+
sdk_version: 3.39.0
|
31 |
+
app_file: app.py
|
32 |
+
emoji: π
|
33 |
+
colorFrom: green
|
34 |
+
colorTo: blue
|
35 |
+
---
|
36 |
+
\`\`\`
|
37 |
+
|
38 |
+
The app is about: ${prompt}`,
|
39 |
+
}
|
40 |
+
]
|
41 |
+
|
42 |
+
return { prefix, files: [], instructions }
|
43 |
+
}
|
src/{getPythonApp.mts β getStreamlitApp.mts}
RENAMED
@@ -1,6 +1,6 @@
|
|
1 |
import { streamlitDoc } from "./streamlitDoc.mts";
|
2 |
|
3 |
-
export function
|
4 |
const prefix = "# In app.py:\n```"
|
5 |
|
6 |
const instructions = [
|
|
|
1 |
import { streamlitDoc } from "./streamlitDoc.mts";
|
2 |
|
3 |
+
export function getStreamlitApp(prompt: string) {
|
4 |
const prefix = "# In app.py:\n```"
|
5 |
|
6 |
const instructions = [
|
src/gradioDoc.mts
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export const streamlitDoc = `
|
2 |
+
# Gradio Code Example
|
3 |
+
|
4 |
+
\`\`\`python
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
def tax_calculator(income, marital_status, assets):
|
8 |
+
tax_brackets = [(10, 0), (25, 8), (60, 12), (120, 20), (250, 30)]
|
9 |
+
total_deductible = sum(assets["Cost"])
|
10 |
+
taxable_income = income - total_deductible
|
11 |
+
|
12 |
+
total_tax = 0
|
13 |
+
for bracket, rate in tax_brackets:
|
14 |
+
if taxable_income > bracket:
|
15 |
+
total_tax += (taxable_income - bracket) * rate / 100
|
16 |
+
|
17 |
+
if marital_status == "Married":
|
18 |
+
total_tax *= 0.75
|
19 |
+
elif marital_status == "Divorced":
|
20 |
+
total_tax *= 0.8
|
21 |
+
|
22 |
+
return round(total_tax)
|
23 |
+
|
24 |
+
demo = gr.Interface(
|
25 |
+
tax_calculator,
|
26 |
+
[
|
27 |
+
"number",
|
28 |
+
gr.Radio(["Single", "Married", "Divorced"]),
|
29 |
+
gr.Dataframe(
|
30 |
+
headers=["Item", "Cost"],
|
31 |
+
datatype=["str", "number"],
|
32 |
+
label="Assets Purchased this Year",
|
33 |
+
),
|
34 |
+
],
|
35 |
+
"number",
|
36 |
+
examples=[
|
37 |
+
[10000, "Married", [["Suit", 5000], ["Laptop", 800], ["Car", 1800]]],
|
38 |
+
[80000, "Single", [["Suit", 800], ["Watch", 1800], ["Car", 800]]],
|
39 |
+
],
|
40 |
+
)
|
41 |
+
|
42 |
+
demo.launch()
|
43 |
+
\`\`\`
|
44 |
+
`
|
src/{isPythonAppPrompt.mts β isPythonOrGradioAppPrompt.mts}
RENAMED
@@ -1,6 +1,5 @@
|
|
1 |
-
export function
|
2 |
const lowerCasePrompt = prompt.toLocaleLowerCase()
|
3 |
return lowerCasePrompt.includes("python")
|
4 |
-
|| lowerCasePrompt.includes("streamlit")
|
5 |
|| lowerCasePrompt.includes("gradio")
|
6 |
}
|
|
|
1 |
+
export function isPythonOrGradioAppPrompt(prompt: string) {
|
2 |
const lowerCasePrompt = prompt.toLocaleLowerCase()
|
3 |
return lowerCasePrompt.includes("python")
|
|
|
4 |
|| lowerCasePrompt.includes("gradio")
|
5 |
}
|
src/isStreamlitAppPrompt.mts
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export function isStreamlitAppPrompt(prompt: string) {
|
2 |
+
const lowerCasePrompt = prompt.toLocaleLowerCase()
|
3 |
+
return lowerCasePrompt.includes("streamlit")
|
4 |
+
}
|