iAIChat commited on
Commit
10ecb91
·
1 Parent(s): a4c0bf7

Update gradio_exit.py

Browse files
Files changed (1) hide show
  1. gradio_exit.py +6 -17
gradio_exit.py CHANGED
@@ -8,14 +8,12 @@ import base64
8
  from dotenv import load_dotenv, find_dotenv
9
 
10
  _ = load_dotenv(find_dotenv()) # read local .env file
11
- hf_api_key =os.getenv(hf_api_key)
12
 
13
- #model_id = "shleifer/distilbart-cnn-12-6"
14
- model_id = "flan-t5-base-text_summarization_data"
15
 
16
- api_url ='https://api-inference.huggingface.co/models/DunnBC22/{model_id}'
17
-
18
- headers = {"Authorization": f"Bearer {hf_api_key}"}
19
 
20
  def get_completion(inputs, parameters=None, ENDPOINT_URL=api_url):
21
  headers = {
@@ -31,16 +29,7 @@ def get_completion(inputs, parameters=None, ENDPOINT_URL=api_url):
31
  )
32
  return json.loads(response.content.decode("utf-8"))
33
 
34
- text = (
35
- '''Alexander III of Macedon (Ancient Greek: Ἀλέξανδρος, romanized: Alexandros; 20/21 July 356 BC – 10/11 June 323 BC), '''
36
- '''commonly known as Alexander the Great,[a] was a king of the ancient Greek kingdom of Macedon.[a] '''
37
- '''He succeeded his father Philip II to the throne in 336 BC at the age of 20, '''
38
- '''and spent most of his ruling years conducting a lengthy military campaign throughout Western Asia and Egypt. '''
39
- '''By the age of 30, he had created one of the largest empires in history, stretching from Greece to northwestern India.[2] '''
40
- '''He was undefeated in battle and is widely considered to be one of history's greatest and most successful military commanders.[3][4]'''
41
- )
42
-
43
- get_completion(text)
44
 
45
  import gradio as gr
46
 
@@ -53,7 +42,7 @@ gr.close_all()
53
  demo = gr.Interface(fn=summarize,
54
  inputs=[gr.Textbox(label="Text to summarize", lines=6)],
55
  outputs=[gr.Textbox(label="Result", lines=3)],
56
- title="Text summarization with distilbart-cnn",
57
  description="Summarize any text using the `shleifer/distilbart-cnn-12-6` model under the hood!"
58
  )
59
 
 
8
  from dotenv import load_dotenv, find_dotenv
9
 
10
  _ = load_dotenv(find_dotenv()) # read local .env file
 
11
 
12
+ model_id = os.getenv(model_id)
13
+ hf_api_key = os.getenv(hf_api_key)
14
 
15
+ #api_url ="https://api-inference.huggingface.co/models/DunnBC22/flan-t5-base-text_summarization_data"
16
+ api_url =f"https://api-inference.huggingface.co/models/DunnBC22/{model_id}"
 
17
 
18
  def get_completion(inputs, parameters=None, ENDPOINT_URL=api_url):
19
  headers = {
 
29
  )
30
  return json.loads(response.content.decode("utf-8"))
31
 
32
+ get_completion(text)
 
 
 
 
 
 
 
 
 
33
 
34
  import gradio as gr
35
 
 
42
  demo = gr.Interface(fn=summarize,
43
  inputs=[gr.Textbox(label="Text to summarize", lines=6)],
44
  outputs=[gr.Textbox(label="Result", lines=3)],
45
+ title="基于HF requests.request的文本总结AI App/Text summarization with distilbart-cnn",
46
  description="Summarize any text using the `shleifer/distilbart-cnn-12-6` model under the hood!"
47
  )
48