command
install
Example
1st example
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
import gradio as gr
def rStr(text): return text.replace("morning", "night")
grobj = gr.Interface(fn = rStr, inputs = gr.Textbox(), outputs = gr.Textbox())
grobj.launch()
|
public run
local run
QR code Brave
QR code Chrome
萌典 Web App
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
import gradio as gr import requests import json
def rStr(word): reStr = "" url = f"https://www.moedict.tw/uni/{word}" resp = requests.get(url) if resp and resp.status_code == 200: info = json.loads(resp.text) print(f"查詢字詞:{info['title']}\n") reStr += f"查詢字詞:{info['title']}\n" reStr += f"部首:{info['radical']}\n" reStr += f"筆畫:{info['stroke_count']}\n" for index, data in enumerate(info['heteronyms']): reStr += f"[{index+1}]" reStr += f" 注音:{data['bopomofo']}\n" reStr += f" 羅馬拼音:{data['bopomofo2']}\n" reStr += f" 漢語拼音:{data['pinyin']}\n" for i, item in enumerate(data['definitions']): reStr += f" ({i+1}):{item['def']}\n" if "type" in item: reStr += f" 詞性:{item['type']}\n" if "example" in item: reStr += f" 解釋:{item['example']}\n" if "quote" in item: reStr += f" 引用:{item['quote']}\n" if "link" in item: reStr += f" 參考\n" for ref in item['link']: reStr += f" {ref}\n"
return reStr
grobj = gr.Interface(fn = rStr, inputs = gr.Textbox(), outputs = gr.Textbox())
grobj.launch()
|
Ref