gptaibox commited on
Commit
d8f1bff
1 Parent(s): 79c5563

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -10,19 +10,22 @@ import requests
10
  # define the text summarizer function
11
  def text_prompt(request, system_role, page_url, api_key, temp):
12
  try:
13
- headers = {'User-Agent': 'Chrome/83.0.4103.106'}
14
- response = requests.get(page_url, headers=headers)
15
- html = response.text
16
 
17
- page = Article('')
18
- page.set_html(html)
19
- page.parse()
 
 
 
 
20
 
21
  except Exception as e:
22
  return "", f"--- An error occurred while processing the URL: {e} ---", ""
23
 
24
  tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
25
- sentences = page.text.split('.')
 
26
 
27
  tokens = []
28
  page_text = ""
@@ -79,7 +82,7 @@ iface = gr.Interface(
79
  gr.Slider(0.0,1.0, value=0.7, label="Temperature:")
80
  ],
81
  outputs=[gr.Textbox(label="Output:"), gr.Markdown(label="Output:"), gr.Markdown(label="Total Tokens:")],
82
- examples=[["Resumen el siguiente texto en un máximo de 100 palabras.", "Actuar como consultor de negocio. La respuesta deberá aparentar ser novedosa. Formatea la respuesta en Markdown. El texto deberá ser traducido siempre al español. Deberás añadir al final una lista de topics del texto en forma de lista separada por comas.", "https://blog.google/outreach-initiatives/google-org/our-commitment-on-using-ai-to-accelerate-progress-on-global-development-goals/","",0.3],
83
  ["Generate a summary of the following text. Give me an overview of the main business impact from the text following this template:\n- Summary:\n- Business Impact:\n- Companies:", "Act as a Business Consultant", "https://ai.googleblog.com/2019/10/quantum-supremacy-using-programmable.html","",0.7],
84
  ["Generate the next insights based on the following text. Indicates N/A if the information is not available in the text.\n- Summary:\n- Acquisition Price:\n- Why is this important for the acquirer:\n- Business Line for the acquirer:\n- Tech Focus for the acquired (list):","Act as a Business Consultant", "https://techcrunch.com/2022/09/28/eqt-acquires-billtrust-a-company-automating-the-invoice-to-cash-process-for-1-7b/","",0.3]
85
  ],
 
10
  # define the text summarizer function
11
  def text_prompt(request, system_role, page_url, api_key, temp):
12
  try:
13
+ USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0'
 
 
14
 
15
+ config = Config()
16
+ config.browser_user_agent = USER_AGENT
17
+ config.request_timeout = 10
18
+
19
+ article = Article(page_url, config=config)
20
+ article.download()
21
+ article.parse()
22
 
23
  except Exception as e:
24
  return "", f"--- An error occurred while processing the URL: {e} ---", ""
25
 
26
  tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
27
+ #TODO: for chinese, separator is ''
28
+ sentences = article.text.split('.')
29
 
30
  tokens = []
31
  page_text = ""
 
82
  gr.Slider(0.0,1.0, value=0.7, label="Temperature:")
83
  ],
84
  outputs=[gr.Textbox(label="Output:"), gr.Markdown(label="Output:"), gr.Markdown(label="Total Tokens:")],
85
+ examples=[["请用简体中文生成一段200字的摘要,并提取5个关键词.", "作为新闻编辑", "https://openai.com/blog/planning-for-agi-and-beyond","",0.7],
86
  ["Generate a summary of the following text. Give me an overview of the main business impact from the text following this template:\n- Summary:\n- Business Impact:\n- Companies:", "Act as a Business Consultant", "https://ai.googleblog.com/2019/10/quantum-supremacy-using-programmable.html","",0.7],
87
  ["Generate the next insights based on the following text. Indicates N/A if the information is not available in the text.\n- Summary:\n- Acquisition Price:\n- Why is this important for the acquirer:\n- Business Line for the acquirer:\n- Tech Focus for the acquired (list):","Act as a Business Consultant", "https://techcrunch.com/2022/09/28/eqt-acquires-billtrust-a-company-automating-the-invoice-to-cash-process-for-1-7b/","",0.3]
88
  ],