Spaces:
Build error
Build error
Update gradio_exit.py
Browse files- gradio_exit.py +3 -41
gradio_exit.py
CHANGED
|
@@ -1,26 +1,3 @@
|
|
| 1 |
-
#https://stackoverflow.com/questions/75286784/how-do-i-gracefully-close-terminate-gradio-from-within-gradio-blocks
|
| 2 |
-
#https://levelup.gitconnected.com/bringing-your-ai-models-to-life-an-introduction-to-gradio-ae051ca83edf
|
| 3 |
-
#Bringing Your AI Models to Life: An Introduction to Gradio - How to demo your ML model quickly without any front-end hassle.
|
| 4 |
-
#pipreqs . --encoding=utf-8
|
| 5 |
-
|
| 6 |
-
#https://huggingface.co/blog/inference-endpoints
|
| 7 |
-
#Getting Started with Hugging Face Inference Endpoints
|
| 8 |
-
|
| 9 |
-
#https://www.gradio.app/guides/using-hugging-face-integrations
|
| 10 |
-
Using Hugging Face Integrations
|
| 11 |
-
|
| 12 |
-
#在app.py的根目录下cmd命令行窗口中运行:gradio deploy,将会出现如下提示:
|
| 13 |
-
#To login, `huggingface_hub` requires a token generated from https://huggingface.co/settings/tokens .
|
| 14 |
-
#Token can be pasted using 'Right-Click'.
|
| 15 |
-
#Token:先将HF_API_TOKEN拷贝到剪贴板之后,邮件单击即可
|
| 16 |
-
#Add token as git credential? (Y/n) n
|
| 17 |
-
#Token is valid (permission: write).
|
| 18 |
-
#Your token has been saved to C:\Users\lenovo\.cache\huggingface\token
|
| 19 |
-
#Login successful
|
| 20 |
-
#Creating new Spaces Repo in 'D:\ChatGPTApps\Gradio_HF_Apps'. Collecting metadata, press Enter to accept default value.
|
| 21 |
-
#Enter Spaces app title [Gradio_HF_Apps]:
|
| 22 |
-
|
| 23 |
-
|
| 24 |
import os
|
| 25 |
import io
|
| 26 |
import requests
|
|
@@ -33,22 +10,12 @@ from dotenv import load_dotenv, find_dotenv
|
|
| 33 |
_ = load_dotenv(find_dotenv()) # read local .env file
|
| 34 |
hf_api_key ="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"
|
| 35 |
|
| 36 |
-
#model_id = "sentence-transformers/all-MiniLM-L6-v2"
|
| 37 |
model_id = "shleifer/distilbart-cnn-12-6"
|
| 38 |
-
#hf_token = "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"
|
| 39 |
|
| 40 |
-
#ENDPOINT_URL='https://api-inference.huggingface.co/models/DunnBC22/flan-t5-base-text_summarization_data'
|
| 41 |
api_url ='https://api-inference.huggingface.co/models/DunnBC22/flan-t5-base-text_summarization_data'
|
| 42 |
-
#api_url = f"https://api-inference.huggingface.co/pipeline/feature-extraction/{model_id}"
|
| 43 |
-
#pipeline的api-inference/Endpoint是对应于transformers(用于生成向量Embeddings)的!
|
| 44 |
-
#headers = {"Authorization": f"Bearer {hf_token}"}
|
| 45 |
-
headers = {"Authorization": f"Bearer {hf_api_key}"}
|
| 46 |
|
| 47 |
-
|
| 48 |
-
# response = requests.post(api_url, headers=headers, json={"inputs": texts, "options":{"wait_for_model":True}})
|
| 49 |
-
# return response.json()
|
| 50 |
|
| 51 |
-
#可以不使用ENDPOINT_URL,而是使用api_url(或者两个是一回事?):https://huggingface.co/blog/getting-started-with-embeddings
|
| 52 |
def get_completion(inputs, parameters=None, ENDPOINT_URL=api_url):
|
| 53 |
headers = {
|
| 54 |
"Authorization": f"Bearer {hf_api_key}",
|
|
@@ -72,7 +39,7 @@ text = (
|
|
| 72 |
'''He was undefeated in battle and is widely considered to be one of history's greatest and most successful military commanders.[3][4]'''
|
| 73 |
)
|
| 74 |
|
| 75 |
-
get_completion(text)
|
| 76 |
|
| 77 |
import gradio as gr
|
| 78 |
|
|
@@ -89,9 +56,4 @@ demo = gr.Interface(fn=summarize,
|
|
| 89 |
description="Summarize any text using the `shleifer/distilbart-cnn-12-6` model under the hood!"
|
| 90 |
)
|
| 91 |
|
| 92 |
-
|
| 93 |
-
#demo.launch(share=True)
|
| 94 |
-
demo.launch()
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import io
|
| 3 |
import requests
|
|
|
|
| 10 |
_ = load_dotenv(find_dotenv()) # read local .env file
|
| 11 |
hf_api_key ="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"
|
| 12 |
|
|
|
|
| 13 |
model_id = "shleifer/distilbart-cnn-12-6"
|
|
|
|
| 14 |
|
|
|
|
| 15 |
api_url ='https://api-inference.huggingface.co/models/DunnBC22/flan-t5-base-text_summarization_data'
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
headers = {"Authorization": f"Bearer {hf_api_key}"}
|
|
|
|
|
|
|
| 18 |
|
|
|
|
| 19 |
def get_completion(inputs, parameters=None, ENDPOINT_URL=api_url):
|
| 20 |
headers = {
|
| 21 |
"Authorization": f"Bearer {hf_api_key}",
|
|
|
|
| 39 |
'''He was undefeated in battle and is widely considered to be one of history's greatest and most successful military commanders.[3][4]'''
|
| 40 |
)
|
| 41 |
|
| 42 |
+
get_completion(text)
|
| 43 |
|
| 44 |
import gradio as gr
|
| 45 |
|
|
|
|
| 56 |
description="Summarize any text using the `shleifer/distilbart-cnn-12-6` model under the hood!"
|
| 57 |
)
|
| 58 |
|
| 59 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|