admin commited on
Commit
6860015
·
1 Parent(s): 6fea553
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -22,20 +22,24 @@ def infer(longUrl: str):
22
  status = "Success"
23
  shortUrl = preview = None
24
  try:
25
- response = requests.post(
26
- API_URL, json={"url": longUrl}, headers=HEADER)
27
  if response.status_code == 200:
28
  shortUrl = json.loads(response.text)["shortUrl"]
29
  else:
30
  raise ConnectionError(response.text)
31
 
32
  if is_valid_url(shortUrl):
33
- preview = f'<a href="{shortUrl}" target="_blank">{shortUrl}</a>'
 
 
 
 
 
34
 
35
  except Exception as e:
36
  status = f"{e}"
37
 
38
- return status, shortUrl, preview
39
 
40
 
41
  if __name__ == "__main__":
@@ -47,15 +51,10 @@ if __name__ == "__main__":
47
  ),
48
  outputs=[
49
  gr.Textbox(label=_L("状态栏"), show_copy_button=True),
50
- gr.Textbox(label=_L("输出短链接"), show_copy_button=True),
51
- gr.HTML(
52
- container=True,
53
- show_label=True,
54
- label=_L("预览短链接"),
55
- ),
56
  ],
57
  flagging_mode="never",
58
  examples=["https://www.bing.com", "https://www.baidu.com"],
59
  cache_examples=False,
60
- title=_L("短链接生成")
61
  ).launch()
 
22
  status = "Success"
23
  shortUrl = preview = None
24
  try:
25
+ response = requests.post(API_URL, json={"url": longUrl}, headers=HEADER)
 
26
  if response.status_code == 200:
27
  shortUrl = json.loads(response.text)["shortUrl"]
28
  else:
29
  raise ConnectionError(response.text)
30
 
31
  if is_valid_url(shortUrl):
32
+ preview = f"""
33
+ {_L("输出短链接")}: <{shortUrl}>
34
+ ```txt
35
+ {shortUrl}
36
+ ```
37
+ """
38
 
39
  except Exception as e:
40
  status = f"{e}"
41
 
42
+ return status, preview
43
 
44
 
45
  if __name__ == "__main__":
 
51
  ),
52
  outputs=[
53
  gr.Textbox(label=_L("状态栏"), show_copy_button=True),
54
+ gr.Markdown(container=True),
 
 
 
 
 
55
  ],
56
  flagging_mode="never",
57
  examples=["https://www.bing.com", "https://www.baidu.com"],
58
  cache_examples=False,
59
+ title=_L("短链接生成"),
60
  ).launch()