|
import gradio as gr |
|
import json |
|
import asyncio |
|
import os |
|
from EdgeGPT import Chatbot, ConversationStyle |
|
|
|
|
|
|
|
|
|
|
|
async def get_model_reply(prompt,style,cookies,context=[]): |
|
|
|
context += [prompt] |
|
cookies = json.loads(cookies) |
|
|
|
|
|
bot = Chatbot(cookies=cookies) |
|
raw_data = await bot.ask(prompt, conversation_style=style) |
|
await bot.close() |
|
|
|
response = raw_data["item"]["messages"][1]["text"] |
|
context += [response] |
|
|
|
|
|
responses = [(u, b) for u, b in zip(context[::2], context[1::2])] |
|
|
|
return responses, context |
|
|
|
|
|
|
|
|
|
|
|
|
|
with gr.Blocks() as dialog_app: |
|
with gr.Tab("Cookies"): |
|
cookies = gr.Textbox(lines=2, label="输入bing.com中的cookies") |
|
with gr.Tab("New Bing Chat"): |
|
gr.Markdown("# A Simple Web to use New Bing Without Magic") |
|
chatbot = gr.Chatbot() |
|
state = gr.State([]) |
|
markdown = gr.Markdown(label="Output") |
|
|
|
with gr.Row(): |
|
inputs = gr.Textbox( |
|
label="输入问题", |
|
placeholder="输入文本,然后按回车键" |
|
) |
|
style = gr.Dropdown(label="回答倾向", choices=["创造", "平衡", "精确"], multiselect=False, |
|
value="balanced", type="value") |
|
|
|
inputs.submit(get_model_reply, [inputs, style, cookies, state], [chatbot, state]) |
|
send = gr.Button("Send") |
|
send.click(get_model_reply, [inputs, style, cookies, state], [chatbot, state]) |
|
|
|
|
|
dialog_app.launch() |
|
|
|
|