Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My project encountered some errors when running after upgrading from version 3 to version 4 of Gradio #7092

Closed
1 task done
SunJR24 opened this issue Jan 21, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@SunJR24
Copy link

SunJR24 commented Jan 21, 2024

Describe the bug

My project initially ran in a graphical environment of=3.30.0, but later upgraded to 4.15 due to the need to add features. After the upgrade, the first step was to run the report error AttributeError: 'Textbox' object has no attribute 'style'. I tried to modify the code, removed the style function, resolved the error, and the webpage graph can be opened normally. But a new problem appeared again. After entering my question in the dialog box, the chatbot's answer was only replied to in the command box, not on the webpage Graph. At the same time, my command to clear the input box in gr.update was only executed once and no longer executed. But the program is running normally without any errors or termination.

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

from transformers import AutoModel, AutoTokenizer
import gradio as gr
import mdtex2html
import os

tokenizer = AutoTokenizer.from_pretrained(".\model", trust_remote_code=True)
model = AutoModel.from_pretrained(".\model", trust_remote_code=True).quantize(4).half().cuda()
model = model.eval()

"""Override Chatbot.postprocess"""

def postprocess(self, y):
if y is None:
return []
for i, (message, response) in enumerate(y):
y[i] = (
None if message is None else mdtex2html.convert((message)),
None if response is None else mdtex2html.convert(response),
)
return y

gr.Chatbot.postprocess = postprocess

def parse_text(text):
"""copy from https://github.com/GaiZhenbiao/ChuanhuChatGPT/"""
lines = text.split("\n")
lines = [line for line in lines if line != ""]
count = 0
for i, line in enumerate(lines):
if "```" in line:
count += 1
items = line.split('') if count % 2 == 1: lines[i] = f'<pre><code class="language-{items[-1]}">' else: lines[i] = f'<br></code></pre>' else: if i > 0: if count % 2 == 1: line = line.replace("", "`")
line = line.replace("<", "<")
line = line.replace(">", ">")
line = line.replace(" ", " ")
line = line.replace("*", "*")
line = line.replace("_", "_")
line = line.replace("-", "-")
line = line.replace(".", ".")
line = line.replace("!", "!")
line = line.replace("(", "(")
line = line.replace(")", ")")
line = line.replace("$", "$")
lines[i] = "
"+line
text = "".join(lines)
return text

def predict(input, chatbot, max_length, top_p, temperature, history):
chatbot.append((parse_text(input), ""))
for response, history in model.stream_chat(tokenizer, input, history, max_length=max_length, top_p=top_p,
temperature=temperature):
chatbot[-1] = (parse_text(input), parse_text(response))

    yield chatbot, history
   # 提取最后一个对话记录				//(第66-67行,last要与61行for对齐)
last_input, last_generated = chatbot[-1]
last_input = last_input.replace("<p>", "").replace("</p>", "")
last_generated = last_generated.replace("<p>", "").replace("</p>", "")

# 打印最后一个对话记录
print("输入: ", last_input)
print("回复: ", last_generated)

def reset_user_input():
return gr.update(value='')

def reset_state():
return [], []

with gr.Blocks() as demo:
gr.HTML("""

ChatGLM

""")

chatbot = gr.Chatbot()
with gr.Row():
    with gr.Column(scale=4):
        with gr.Column(scale=12):
            user_input = gr.Textbox(show_label=False, placeholder="Input...", lines=10, container=False)
        with gr.Column(min_width=32, scale=1):
            submitBtn = gr.Button("Submit", variant="primary")
    with gr.Column(scale=1):
        emptyBtn = gr.Button("Clear History")
        max_length = gr.Slider(0, 4096, value=2048, step=1.0, label="Maximum length", interactive=True)
        top_p = gr.Slider(0, 1, value=0.7, step=0.01, label="Top P", interactive=True)
        temperature = gr.Slider(0, 1, value=0.95, step=0.01, label="Temperature", interactive=True)

history = gr.State([])

submitBtn.click(predict, [user_input, chatbot, max_length, top_p, temperature, history], [chatbot, history],
                show_progress=True)
# submitBtn.click(reset_user_input, [], [user_input])

emptyBtn.click(reset_state, outputs=[chatbot, history], show_progress=True)

demo.queue().launch(share=False, inbrowser=True)

Screenshot

7bd1c6e91fb91835f7b9dc5fb933659

Logs

No response

System Info

old gradio==3.30.0 can work,gradio==4.15.0 get those questions

Severity

Blocking usage of gradio

@SunJR24 SunJR24 added the bug Something isn't working label Jan 21, 2024
@Bharath-12205425
Copy link

Textbook object having no attribute style

@abidlabs
Copy link
Member

Hi @SunJR24 @Bharath-12205425 the style method was deprecated and removed in 4.0. Can you please consult this pinned issue to migrate from 3.x to 4.x:

#6339

If you still are experiencing issues, please provide a minimal repro with correctly formatted code that we can use to help you. As it stands, this issue includes too much code and incorrect formatting making it difficult to parse so I’ll close this issue for now, but can reopen if you please address these points.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants