Spaces:
Sleeping
Sleeping
anvil version of run
Browse files- .ipynb_checkpoints/app-checkpoint.py +0 -18
- app.py +13 -0
- out.txt +10 -15
- scripts/update_valdata.py +1 -1
- test.ipynb +89 -5
.ipynb_checkpoints/app-checkpoint.py
DELETED
@@ -1,18 +0,0 @@
|
|
1 |
-
from flask import Flask,request,render_template
|
2 |
-
import os
|
3 |
-
|
4 |
-
app=Flask(__name__)
|
5 |
-
|
6 |
-
@app.route('/', methods=['GET', 'POST'])
|
7 |
-
def home():
|
8 |
-
return render_template
|
9 |
-
def run_script():
|
10 |
-
script=request.args.get('script')
|
11 |
-
os.system(script+' > ./out.txt')
|
12 |
-
with open('./out.txt','r') as f: output=f.read()
|
13 |
-
return output
|
14 |
-
|
15 |
-
if __name__=='__main__':
|
16 |
-
app.run()
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
@@ -6,11 +6,24 @@ import os
|
|
6 |
anvil.server.connect('55MH4EBKM22EP4E6D5T6CVSL-VGO5X4SM6JEXGJVT')
|
7 |
import json
|
8 |
import ast
|
|
|
9 |
def run_script(scriptname):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
os.system(scriptname+' > ./out.txt')
|
11 |
with open('./out.txt','r') as f: output=f.read()
|
12 |
return output
|
13 |
|
|
|
|
|
|
|
|
|
|
|
14 |
gradio_interface = gr.Interface(
|
15 |
fn=run_script,
|
16 |
inputs="text",
|
|
|
6 |
anvil.server.connect('55MH4EBKM22EP4E6D5T6CVSL-VGO5X4SM6JEXGJVT')
|
7 |
import json
|
8 |
import ast
|
9 |
+
|
10 |
def run_script(scriptname):
|
11 |
+
# return scriptname
|
12 |
+
os.system(scriptname+' > ./out.txt')
|
13 |
+
with open('./out.txt','r') as f: output=f.read()
|
14 |
+
return output
|
15 |
+
|
16 |
+
@anvil.server.callable
|
17 |
+
def run_command(scriptname):
|
18 |
os.system(scriptname+' > ./out.txt')
|
19 |
with open('./out.txt','r') as f: output=f.read()
|
20 |
return output
|
21 |
|
22 |
+
@anvil.server.callable
|
23 |
+
def get_file(filename):
|
24 |
+
m = BlobMedia('text/plain', 'Hello, world!', name='hello.txt')
|
25 |
+
return m
|
26 |
+
|
27 |
gradio_interface = gr.Interface(
|
28 |
fn=run_script,
|
29 |
inputs="text",
|
out.txt
CHANGED
@@ -1,15 +1,10 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
gmserver_old
|
12 |
-
index.pickle
|
13 |
-
llama
|
14 |
-
test.py
|
15 |
-
trystuff.ipynb
|
|
|
1 |
+
total 56
|
2 |
+
8 -rw-r--r-- 1 a112956 staff 621 Nov 13 15:08 README.md
|
3 |
+
0 drwxr-xr-x 5 a112956 staff 160 Nov 13 15:07 __pycache__
|
4 |
+
8 -rw-r--r--@ 1 a112956 staff 1208 Nov 13 16:00 app.py
|
5 |
+
0 drwxr-xr-x 2 a112956 staff 64 Nov 13 15:15 flagged
|
6 |
+
0 -rw-r--r-- 1 a112956 staff 0 Nov 13 16:02 out.txt
|
7 |
+
8 -rw-r--r-- 1 a112956 staff 22 Nov 13 15:21 requirements.txt
|
8 |
+
0 drwxr-xr-x 3 a112956 staff 96 Nov 13 15:19 scripts
|
9 |
+
24 -rw-r--r-- 1 a112956 staff 9239 Nov 13 15:56 test.ipynb
|
10 |
+
8 -rw-r--r-- 1 a112956 staff 12 Nov 13 15:08 update.txt
|
|
|
|
|
|
|
|
|
|
scripts/update_valdata.py
CHANGED
@@ -14,7 +14,7 @@ import numpy as np
|
|
14 |
|
15 |
|
16 |
napi = NumerAPI()
|
17 |
-
data_path='./
|
18 |
|
19 |
|
20 |
# In[ ]:
|
|
|
14 |
|
15 |
|
16 |
napi = NumerAPI()
|
17 |
+
data_path='./data/'
|
18 |
|
19 |
|
20 |
# In[ ]:
|
test.ipynb
CHANGED
@@ -2,8 +2,10 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
-
"metadata": {
|
|
|
|
|
7 |
"outputs": [],
|
8 |
"source": [
|
9 |
"import requests\n",
|
@@ -12,6 +14,88 @@
|
|
12 |
"import pandas as pd"
|
13 |
]
|
14 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
{
|
16 |
"cell_type": "code",
|
17 |
"execution_count": 3,
|
@@ -63,7 +147,7 @@
|
|
63 |
],
|
64 |
"metadata": {
|
65 |
"kernelspec": {
|
66 |
-
"display_name": "
|
67 |
"language": "python",
|
68 |
"name": "python3"
|
69 |
},
|
@@ -77,9 +161,9 @@
|
|
77 |
"name": "python",
|
78 |
"nbconvert_exporter": "python",
|
79 |
"pygments_lexer": "ipython3",
|
80 |
-
"version": "3.
|
81 |
}
|
82 |
},
|
83 |
"nbformat": 4,
|
84 |
-
"nbformat_minor":
|
85 |
}
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 5,
|
6 |
+
"metadata": {
|
7 |
+
"tags": []
|
8 |
+
},
|
9 |
"outputs": [],
|
10 |
"source": [
|
11 |
"import requests\n",
|
|
|
14 |
"import pandas as pd"
|
15 |
]
|
16 |
},
|
17 |
+
{
|
18 |
+
"cell_type": "code",
|
19 |
+
"execution_count": 15,
|
20 |
+
"metadata": {
|
21 |
+
"tags": []
|
22 |
+
},
|
23 |
+
"outputs": [],
|
24 |
+
"source": [
|
25 |
+
"url='https://gmshroff-gmserver.hf.space/run/predict'\n",
|
26 |
+
"# url='http://127.0.0.1:7860'\n",
|
27 |
+
"hf_token='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'"
|
28 |
+
]
|
29 |
+
},
|
30 |
+
{
|
31 |
+
"cell_type": "code",
|
32 |
+
"execution_count": 16,
|
33 |
+
"metadata": {
|
34 |
+
"tags": []
|
35 |
+
},
|
36 |
+
"outputs": [
|
37 |
+
{
|
38 |
+
"name": "stdout",
|
39 |
+
"output_type": "stream",
|
40 |
+
"text": [
|
41 |
+
"Loaded as API: https://gmshroff-gmserver.hf.space/run/predict/ ✔\n"
|
42 |
+
]
|
43 |
+
},
|
44 |
+
{
|
45 |
+
"ename": "ValueError",
|
46 |
+
"evalue": "Could not get Gradio config from: https://gmshroff-gmserver.hf.space/run/predict/",
|
47 |
+
"output_type": "error",
|
48 |
+
"traceback": [
|
49 |
+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
50 |
+
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
|
51 |
+
"\u001b[0;32m/opt/homebrew/Caskroom/miniforge/base/envs/py38algo/lib/python3.8/site-packages/gradio_client/client.py\u001b[0m in \u001b[0;36m_get_config\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 594\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 595\u001b[0;31m \u001b[0mconfig\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mjson\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloads\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgroup\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# type: ignore\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 596\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mAttributeError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mae\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
52 |
+
"\u001b[0;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'group'",
|
53 |
+
"\nThe above exception was the direct cause of the following exception:\n",
|
54 |
+
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
|
55 |
+
"\u001b[0;32m/var/folders/jz/466kbks91q3glsb0kx0kfwk80000gq/T/ipykernel_75812/2087672778.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mgradio_client\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mClient\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mclient\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mClient\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0murl\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mclient\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"pwd\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mapi_name\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"/predict\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
56 |
+
"\u001b[0;32m/opt/homebrew/Caskroom/miniforge/base/envs/py38algo/lib/python3.8/site-packages/gradio_client/client.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, src, hf_token, max_workers, serialize, output_dir, verbose)\u001b[0m\n\u001b[1;32m 125\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupload_url\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0murllib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mparse\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0murljoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msrc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mutils\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mUPLOAD_URL\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 126\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreset_url\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0murllib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mparse\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0murljoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msrc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mutils\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mRESET_URL\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 127\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconfig\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_get_config\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 128\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msession_hash\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0muuid\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0muuid4\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 129\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
|
57 |
+
"\u001b[0;32m/opt/homebrew/Caskroom/miniforge/base/envs/py38algo/lib/python3.8/site-packages/gradio_client/client.py\u001b[0m in \u001b[0;36m_get_config\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 595\u001b[0m \u001b[0mconfig\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mjson\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloads\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgroup\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# type: ignore\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 596\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mAttributeError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mae\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 597\u001b[0;31m raise ValueError(\n\u001b[0m\u001b[1;32m 598\u001b[0m \u001b[0;34mf\"Could not get Gradio config from: {self.src}\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 599\u001b[0m ) from ae\n",
|
58 |
+
"\u001b[0;31mValueError\u001b[0m: Could not get Gradio config from: https://gmshroff-gmserver.hf.space/run/predict/"
|
59 |
+
]
|
60 |
+
}
|
61 |
+
],
|
62 |
+
"source": [
|
63 |
+
"from gradio_client import Client\n",
|
64 |
+
"\n",
|
65 |
+
"client = Client(url)\n",
|
66 |
+
"result = client.predict(\"pwd\",api_name=\"/predict\",hf_token=hf_token)\n",
|
67 |
+
"result"
|
68 |
+
]
|
69 |
+
},
|
70 |
+
{
|
71 |
+
"cell_type": "code",
|
72 |
+
"execution_count": 35,
|
73 |
+
"metadata": {},
|
74 |
+
"outputs": [],
|
75 |
+
"source": [
|
76 |
+
"response = requests.post(url,json=json.dumps({\"data\":\"ls\"}),headers={'Content-Type':'application/json'})"
|
77 |
+
]
|
78 |
+
},
|
79 |
+
{
|
80 |
+
"cell_type": "code",
|
81 |
+
"execution_count": 36,
|
82 |
+
"metadata": {},
|
83 |
+
"outputs": [
|
84 |
+
{
|
85 |
+
"data": {
|
86 |
+
"text/plain": [
|
87 |
+
"b'{\"detail\":\"Method Not Allowed\"}'"
|
88 |
+
]
|
89 |
+
},
|
90 |
+
"execution_count": 36,
|
91 |
+
"metadata": {},
|
92 |
+
"output_type": "execute_result"
|
93 |
+
}
|
94 |
+
],
|
95 |
+
"source": [
|
96 |
+
"response.content"
|
97 |
+
]
|
98 |
+
},
|
99 |
{
|
100 |
"cell_type": "code",
|
101 |
"execution_count": 3,
|
|
|
147 |
],
|
148 |
"metadata": {
|
149 |
"kernelspec": {
|
150 |
+
"display_name": "Python 3 (ipykernel)",
|
151 |
"language": "python",
|
152 |
"name": "python3"
|
153 |
},
|
|
|
161 |
"name": "python",
|
162 |
"nbconvert_exporter": "python",
|
163 |
"pygments_lexer": "ipython3",
|
164 |
+
"version": "3.8.12"
|
165 |
}
|
166 |
},
|
167 |
"nbformat": 4,
|
168 |
+
"nbformat_minor": 4
|
169 |
}
|