Xinyoumeng233hu's picture
Rename demo.py to app.py
33e4246
raw
history blame
7.01 kB
from run_single import encode_message,decode_message
import gradio as gr
def encode_decode_message(mode, secret_message, chosen_context):
x= encode_message(mode, secret_message, chosen_context)
return x
def decode_encode_message(mode, stegomessage, chosen_context):
y = decode_message(mode, stegomessage, chosen_context)
return y
def clear1():
# en_input2.value = ""
en_method.value = ""
en_output.value = ""
en_ppl.value = ""
en_kl.value = ""
en_wordsbit.value = ""
# en_entropy.value = ""
return "","","","","","",""
def clear2():
# de_input2.value = ""
de_method.value = ""
de_output.value = ""
return "","",""
# Modify the demo block to add Textbox widgets for metrics
with gr.Blocks() as demo:
gr.Markdown("<center><h1>GPT2隐写系统</h1></center>")
gr.Markdown("使用gpt2模型进行隐写与提取.")
with gr.Tab("加密"):
en_input1 = gr.Textbox(label="上下文",placeholder="Input context")
en_input2 = gr.Textbox(label="秘密信息",placeholder="Message text to be concealed")
en_method = gr.Dropdown(label="嵌入算法", choices=["meteor", "arithmetic", "huffman", "bins"])
en_output = gr.Textbox(label="含密文本")
with gr.Row():
en_ppl = gr.Textbox(label="困惑度")
en_kl = gr.Textbox(label="KL散度")
en_wordsbit = gr.Textbox(label="每比特所携带的信息量")
# en_entropy = gr.Textbox(label="信道容量")
with gr.Row():
en_button1 = gr.Button("清除")
en_button2 = gr.Button("加密")
en_input1.value = "Despite a long history of research and wide-spread applications to censorship resistant systems, practical steganographic systems capable of embedding messages into realistic communication distributions, like text, do not exist." #@param ["Washington received his initial military training and command with the Virginia Regiment during the French and Indian War. He was later elected to the Virginia House of Burgesses and was named a delegate to the Continental Congress, where he was appointed Commanding General of the nation's Continental Army. Washington led American forces, allied with France, in the defeat of the British at Yorktown. Once victory for the United States was in hand in 1783, Washington resigned his commission.", "The Alvarez hypothesis posits that the mass extinction of the dinosaurs and many other living things during the Cretaceous-Paleogene extinction event was caused by the impact of a large asteroid on the Earth. Prior to 2013, it was commonly cited as having happened about 65 million years ago, but Renne and colleagues (2013) gave an updated value of 66 million years. Evidence indicates that the asteroid fell in the Yucatan Peninsula, at Chicxulub, Mexico. The hypothesis is named after the father-and-son team of scientists Luis and Walter Alvarez, who first suggested it in 1980. Shortly afterwards, and independently, the same was suggested by Dutch paleontologist Jan Smit.", "Despite a long history of research and wide-spread applications to censorship resistant systems, practical steganographic systems capable of embedding messages into realistic communication distributions, like text, do not exist."] {allow-input: true}
# en_input1.value = "Washington received his initial military training and command with the Virginia Regiment during the French and Indian War. He was later elected to the Virginia House of Burgesses and was named a delegate to the Continental Congress, where he was appointed Commanding General of the nation's Continental Army. Washington led American forces, allied with France, in the defeat of the British at Yorktown. Once victory for the United States was in hand in 1783, Washington resigned his commission."
en_input2.value = "In me the tiger sniffs the tiger."
# en_input2.value = "hello"
with gr.Tab("解密"):
de_input1 = gr.Textbox(label="上下文")
de_input2 = gr.Textbox(label="含密文本",placeholder="Output of encrypt")
de_method = gr.Dropdown(label="嵌入算法",choices=["meteor", "arithmetic", "huffman", "bins"])
de_output = gr.Textbox(label="恢复的秘密信息")
with gr.Row():
de_button1 = gr.Button("清除")
de_button2 = gr.Button("解密")
de_input1.value = "Despite a long history of research and wide-spread applications to censorship resistant systems, practical steganographic systems capable of embedding messages into realistic communication distributions, like text, do not exist." #@param ["Washington received his initial military training and command with the Virginia Regiment during the French and Indian War. He was later elected to the Virginia House of Burgesses and was named a delegate to the Continental Congress, where he was appointed Commanding General of the nation's Continental Army. Washington led American forces, allied with France, in the defeat of the British at Yorktown. Once victory for the United States was in hand in 1783, Washington resigned his commission.", "The Alvarez hypothesis posits that the mass extinction of the dinosaurs and many other living things during the Cretaceous-Paleogene extinction event was caused by the impact of a large asteroid on the Earth. Prior to 2013, it was commonly cited as having happened about 65 million years ago, but Renne and colleagues (2013) gave an updated value of 66 million years. Evidence indicates that the asteroid fell in the Yucatan Peninsula, at Chicxulub, Mexico. The hypothesis is named after the father-and-son team of scientists Luis and Walter Alvarez, who first suggested it in 1980. Shortly afterwards, and independently, the same was suggested by Dutch paleontologist Jan Smit.", "Despite a long history of research and wide-spread applications to censorship resistant systems, practical steganographic systems capable of embedding messages into realistic communication distributions, like text, do not exist."] {allow-input: true}
# de_input1.value = "Washington received his initial military training and command with the Virginia Regiment during the French and Indian War. He was later elected to the Virginia House of Burgesses and was named a delegate to the Continental Congress, where he was appointed Commanding General of the nation's Continental Army. Washington led American forces, allied with France, in the defeat of the British at Yorktown. Once victory for the United States was in hand in 1783, Washington resigned his commission."
en_button1.click(clear1, outputs=[en_output,en_ppl,en_kl,en_wordsbit])
en_button2.click(encode_decode_message, inputs=[en_method, en_input2, en_input1], outputs=[en_output,en_ppl,en_kl,en_wordsbit])
de_button1.click(clear2, outputs=[de_input2,de_output])
de_button2.click(decode_encode_message, inputs=[de_method, de_input2, de_input1], outputs=[de_output])
demo.launch()