morisono
commited on
Upload folder using huggingface_hub
Browse files- README.md +12 -8
- index.html +29 -0
- requirements.txt +1 -0
- scripts/conv.py +66 -0
- src/app/demo.py +8 -0
README.md
CHANGED
@@ -1,12 +1,16 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
|
4 |
-
colorFrom: yellow
|
5 |
-
colorTo: pink
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
---
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
title: glite-pg
|
3 |
+
app_file: src/app/run.py
|
|
|
|
|
4 |
sdk: gradio
|
5 |
+
sdk_version: 3.39.0
|
|
|
|
|
6 |
---
|
7 |
|
8 |
+
# Gradio-lite demo
|
9 |
+
|
10 |
+
- write requirements.txt
|
11 |
+
|
12 |
+
- run convert
|
13 |
+
```sh
|
14 |
+
python scripts/conv.py src/app/demo.py requirements.txt
|
15 |
+
```
|
16 |
+
- share index.html
|
index.html
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<script type="module" crossorigin src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js"></script>
|
5 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css" />
|
6 |
+
</head>
|
7 |
+
<body>
|
8 |
+
<gradio-lite theme="light">
|
9 |
+
<gradio-requirements>
|
10 |
+
|
11 |
+
</gradio-requirements>
|
12 |
+
|
13 |
+
|
14 |
+
<gradio-file name="demo.py" entrypoint>
|
15 |
+
import gradio as gr
|
16 |
+
|
17 |
+
|
18 |
+
def greet(name):
|
19 |
+
return "Hello, " + name + "!"
|
20 |
+
|
21 |
+
|
22 |
+
gr.Interface(greet, "textbox", "textbox").launch()
|
23 |
+
|
24 |
+
</gradio-file>
|
25 |
+
|
26 |
+
</gradio-lite>
|
27 |
+
</body>
|
28 |
+
</html>
|
29 |
+
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
|
scripts/conv.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
import os
|
3 |
+
from datetime import datetime
|
4 |
+
|
5 |
+
def convert_to_gradio_lite(python_files, requirements_file):
|
6 |
+
# gradio-requirements.txt からの依存関係の取得
|
7 |
+
dependencies = []
|
8 |
+
if requirements_file:
|
9 |
+
with open(requirements_file, "r") as file:
|
10 |
+
dependencies = [line.strip() for line in file]
|
11 |
+
|
12 |
+
# Gradio Lite の HTML テンプレートを作成
|
13 |
+
html_template = """
|
14 |
+
<html>
|
15 |
+
<head>
|
16 |
+
<script type="module" crossorigin src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js"></script>
|
17 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css" />
|
18 |
+
</head>
|
19 |
+
<body>
|
20 |
+
<gradio-lite theme="light">
|
21 |
+
<gradio-requirements>
|
22 |
+
{}
|
23 |
+
</gradio-requirements>
|
24 |
+
|
25 |
+
{}
|
26 |
+
</gradio-lite>
|
27 |
+
</body>
|
28 |
+
</html>
|
29 |
+
"""
|
30 |
+
|
31 |
+
# 依存関係を Gradio Lite の HTML に挿入
|
32 |
+
requirements = "\n".join(dependencies)
|
33 |
+
|
34 |
+
# 各 Python ファイルを処理し、<gradio-file> タグを作成
|
35 |
+
gradio_files = []
|
36 |
+
for python_file in python_files:
|
37 |
+
with open(python_file, "r") as file:
|
38 |
+
python_code = file.read()
|
39 |
+
|
40 |
+
entrypoint = "entrypoint" if python_file == python_files[0] else ""
|
41 |
+
gradio_file = f"""
|
42 |
+
<gradio-file name="{os.path.basename(python_file)}" {entrypoint}>
|
43 |
+
{python_code}
|
44 |
+
</gradio-file>
|
45 |
+
"""
|
46 |
+
gradio_files.append(gradio_file)
|
47 |
+
|
48 |
+
# 完成した HTML を返す
|
49 |
+
return html_template.format(requirements, "\n".join(gradio_files))
|
50 |
+
|
51 |
+
# コマンドライン引数からファイルパスを取得
|
52 |
+
python_files = sys.argv[1:-1]
|
53 |
+
requirements_file = sys.argv[-1] if len(sys.argv) > 1 else None
|
54 |
+
|
55 |
+
# Gradio Lite への変換
|
56 |
+
gradio_lite_html = convert_to_gradio_lite(python_files, requirements_file)
|
57 |
+
|
58 |
+
# タイムスタンプ付きのファイル名を生成
|
59 |
+
timestamp = datetime.now().strftime("%Y-%m-%d_%H%M%S")
|
60 |
+
output_file = f"index_{timestamp}.html"
|
61 |
+
|
62 |
+
# 結果をファイルに出力
|
63 |
+
with open(output_file, "w") as file:
|
64 |
+
file.write(gradio_lite_html)
|
65 |
+
|
66 |
+
print(f"Gradio Lite HTML has been generated and saved as {output_file}")
|
src/app/demo.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
|
4 |
+
def greet(name):
|
5 |
+
return "Hello, " + name + "!"
|
6 |
+
|
7 |
+
|
8 |
+
gr.Interface(greet, "textbox", "textbox").launch()
|