Spaces:
Runtime error
Runtime error
nurasaki
commited on
Commit
•
704dc9c
1
Parent(s):
65c2769
gradio_nlp_berta_masked_example: first commit
Browse files- .gitignore +2 -0
- README.md +18 -1
- app.py +71 -0
- favicon.png +0 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
__pycache__/
|
2 |
+
.DS_Store
|
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title: Gradio
|
3 |
emoji: 💻
|
4 |
colorFrom: yellow
|
5 |
colorTo: red
|
@@ -9,4 +9,21 @@ 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 |
+
title: Gradio NLP - Berta Masked Example
|
3 |
emoji: 💻
|
4 |
colorFrom: yellow
|
5 |
colorTo: red
|
|
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
+
|
13 |
+
|
14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
15 |
+
|
16 |
+
```sh git commands
|
17 |
+
git clone https://huggingface.co/spaces/nurasaki/gradio_nlp_berta_masked_example
|
18 |
+
echo __pycache__/ > .gitignore\n
|
19 |
+
git status
|
20 |
+
git add .
|
21 |
+
git commit -am "gradio_nlp_berta_masked_example: first commit"
|
22 |
+
git push
|
23 |
+
|
24 |
+
git remote add gh_repo git@github.com:nurasaki/gradio_nlp_berta_masked_example.git
|
25 |
+
git push gh_repo main
|
26 |
+
```
|
27 |
+
|
28 |
+
|
29 |
+
|
app.py
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
|
4 |
+
# save your HF API token from https:/hf.co/settings/tokens as an env variable to avoid rate limiting
|
5 |
+
auth_token = os.getenv("auth_token")
|
6 |
+
|
7 |
+
|
8 |
+
|
9 |
+
|
10 |
+
print("========================================================================")
|
11 |
+
print("Starting ... gradio_demo_nlp_autocomplete/app.py")
|
12 |
+
print("AUTH TOKEN:", auth_token)
|
13 |
+
|
14 |
+
|
15 |
+
# load a model from https://hf.co/models as an interface, then use it as an api
|
16 |
+
# you can remove the api_key parameter if you don't care about rate limiting.
|
17 |
+
api = gr.Interface.load("huggingface/projecte-aina/roberta-base-ca-v2", api_key=auth_token,)
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
def complete_with_gpt(text):
|
25 |
+
|
26 |
+
print("------------------------------------------------------------------------")
|
27 |
+
print("type(api):", type(api) )
|
28 |
+
print("Api:", api, "\n" )
|
29 |
+
|
30 |
+
|
31 |
+
|
32 |
+
print("------------------------------------------------------------------------")
|
33 |
+
print("text:")
|
34 |
+
print(text)
|
35 |
+
print("------------------------------------------------------------------------")
|
36 |
+
print("text[:-50]:")
|
37 |
+
print(text[:-50])
|
38 |
+
print("------------------------------------------------------------------------")
|
39 |
+
print("api(text):")
|
40 |
+
print(api(text))
|
41 |
+
print("------------------------------------------------------------------------")
|
42 |
+
print("text[-50:]:")
|
43 |
+
print(text[-50:])
|
44 |
+
print("------------------------------------------------------------------------")
|
45 |
+
print("api(text[-50:]")
|
46 |
+
print(api(text[-50:]))
|
47 |
+
print("------------------------------------------------------------------------")
|
48 |
+
|
49 |
+
|
50 |
+
return text[:-50] + api(text[-50:])
|
51 |
+
|
52 |
+
|
53 |
+
with gr.Blocks() as demo:
|
54 |
+
|
55 |
+
print("------------------------------------------------------------------------")
|
56 |
+
print("with gr.Blocks")
|
57 |
+
|
58 |
+
textbox = gr.Textbox(placeholder="Type here...", lines=4)
|
59 |
+
btn = gr.Button("Autocomplete")
|
60 |
+
|
61 |
+
print("textbox:", textbox)
|
62 |
+
|
63 |
+
# define what will run when the button is clicked, here the textbox is used as both an input and an output
|
64 |
+
btn.click(fn=complete_with_gpt, inputs=textbox, outputs=textbox, queue=False)
|
65 |
+
|
66 |
+
demo.launch(favicon_path="favicon.png")
|
67 |
+
|
68 |
+
|
69 |
+
# /Users/nurasaki/miniforge3/envs/conda_tfg_clone/lib/python3.8/site-packages/gradio/interface.py:93:
|
70 |
+
# UserWarning: gr.Intrerface.load() will be deprecated. Use gr.load() instead.
|
71 |
+
# warnings.warn("gr.Intrerface.load() will be deprecated. Use gr.load() instead.")
|
favicon.png
ADDED