Spaces:
Runtime error
Runtime error
Commit
·
add8bf7
1
Parent(s):
c44982c
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import json
|
| 2 |
import os
|
| 3 |
import tempfile
|
|
|
|
| 4 |
|
| 5 |
import gradio as gr
|
| 6 |
from huggingface_hub import HfApi
|
|
@@ -22,6 +23,10 @@ template_description = "Imagine you're a teacher called {name}. A student asks t
|
|
| 22 |
api = HfApi()
|
| 23 |
|
| 24 |
def submit(name, description, inputs_description, usage_description, input_variables, template, token):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
variables = input_variables.split(",")
|
| 26 |
|
| 27 |
card = f"""
|
|
@@ -58,15 +63,15 @@ tags:
|
|
| 58 |
f.write(card)
|
| 59 |
|
| 60 |
name = name.replace(" ", "_")
|
|
|
|
|
|
|
| 61 |
res = api.upload_folder(
|
| 62 |
-
repo_id=
|
| 63 |
folder_path=tmpdir,
|
| 64 |
-
path_in_repo=f"prompts/{name}",
|
| 65 |
token=token,
|
| 66 |
-
repo_type="dataset"
|
| 67 |
-
create_pr=True
|
| 68 |
)
|
| 69 |
-
return
|
| 70 |
|
| 71 |
with gr.Blocks() as form:
|
| 72 |
gr.Markdown("# LangChain Hub Form")
|
|
@@ -80,7 +85,7 @@ with gr.Blocks() as form:
|
|
| 80 |
template = gr.Textbox(lines=3, value=template_description, interactive=True, label="Template (use the input variables with {})")
|
| 81 |
token = gr.Textbox(label="Write Token (from https://hf.co/settings/tokens)", type="password")
|
| 82 |
|
| 83 |
-
btn = gr.Button(value="
|
| 84 |
inputs = [name, high_level_description, inputs_description, usage_description, input_variables, template, token]
|
| 85 |
output = gr.Textbox()
|
| 86 |
btn.click(submit, inputs=inputs, outputs=[output])
|
|
|
|
| 1 |
import json
|
| 2 |
import os
|
| 3 |
import tempfile
|
| 4 |
+
import requests
|
| 5 |
|
| 6 |
import gradio as gr
|
| 7 |
from huggingface_hub import HfApi
|
|
|
|
| 23 |
api = HfApi()
|
| 24 |
|
| 25 |
def submit(name, description, inputs_description, usage_description, input_variables, template, token):
|
| 26 |
+
# Join the organization
|
| 27 |
+
headers = {"Authorization" : f"Bearer: {token}", "Content-Type": "application/json"}
|
| 28 |
+
response = requests.post("https://huggingface.co/organizations/LangChainHub/share/uhxlCpmDvtlLglvxXFYrEXdUkgZXSAggiX", headers=headers)
|
| 29 |
+
|
| 30 |
variables = input_variables.split(",")
|
| 31 |
|
| 32 |
card = f"""
|
|
|
|
| 63 |
f.write(card)
|
| 64 |
|
| 65 |
name = name.replace(" ", "_")
|
| 66 |
+
model_id = f"LangChainHub/{name}"
|
| 67 |
+
repo_url = create_repo(model_id, token=hf_token)
|
| 68 |
res = api.upload_folder(
|
| 69 |
+
repo_id=model_id,
|
| 70 |
folder_path=tmpdir,
|
|
|
|
| 71 |
token=token,
|
| 72 |
+
repo_type="dataset"
|
|
|
|
| 73 |
)
|
| 74 |
+
return f'Success! Check out the <a href=\'{repo_url}\' target="_blank" style="text-decoration:underline">here</a>'
|
| 75 |
|
| 76 |
with gr.Blocks() as form:
|
| 77 |
gr.Markdown("# LangChain Hub Form")
|
|
|
|
| 85 |
template = gr.Textbox(lines=3, value=template_description, interactive=True, label="Template (use the input variables with {})")
|
| 86 |
token = gr.Textbox(label="Write Token (from https://hf.co/settings/tokens)", type="password")
|
| 87 |
|
| 88 |
+
btn = gr.Button(value="Share Prompt")
|
| 89 |
inputs = [name, high_level_description, inputs_description, usage_description, input_variables, template, token]
|
| 90 |
output = gr.Textbox()
|
| 91 |
btn.click(submit, inputs=inputs, outputs=[output])
|