Update app.py
Browse files
app.py
CHANGED
@@ -44,64 +44,28 @@ def generate_response(prompt, history, temperature=0.9, max_new_tokens=256, top_
|
|
44 |
output += response.token.text
|
45 |
yield output, None
|
46 |
|
47 |
-
additional_inputs = [
|
48 |
-
gr.Slider(
|
49 |
-
label="Temperature",
|
50 |
-
value=0.9,
|
51 |
-
minimum=0.0,
|
52 |
-
maximum=1.0,
|
53 |
-
step=0.05,
|
54 |
-
interactive=True,
|
55 |
-
info="Higher values produce more diverse outputs",
|
56 |
-
),
|
57 |
-
gr.Slider(
|
58 |
-
label="Max new tokens",
|
59 |
-
value=256,
|
60 |
-
minimum=0,
|
61 |
-
maximum=1048,
|
62 |
-
step=64,
|
63 |
-
interactive=True,
|
64 |
-
info="The maximum numbers of new tokens",
|
65 |
-
),
|
66 |
-
gr.Slider(
|
67 |
-
label="Top-p (nucleus sampling)",
|
68 |
-
value=0.90,
|
69 |
-
minimum=0.0,
|
70 |
-
maximum=1.0,
|
71 |
-
step=0.05,
|
72 |
-
interactive=True,
|
73 |
-
info="Higher values sample more low-probability tokens",
|
74 |
-
),
|
75 |
-
gr.Slider(
|
76 |
-
label="Repetition penalty",
|
77 |
-
value=1.2,
|
78 |
-
minimum=1.0,
|
79 |
-
maximum=2.0,
|
80 |
-
step=0.05,
|
81 |
-
interactive=True,
|
82 |
-
info="Penalize repeated tokens",
|
83 |
-
)
|
84 |
-
]
|
85 |
-
|
86 |
with gr.Blocks(theme="Nymbo/Alyx_Theme") as demo:
|
87 |
gr.Markdown("# Chatbot with Image Generation")
|
88 |
-
|
89 |
-
chat_history = gr.Chatbot()
|
90 |
-
chat_input = gr.Textbox(label="User Input", placeholder="Type your message here...")
|
91 |
-
chat_output = gr.Textbox(label="Chatbot Response")
|
92 |
-
image_output = gr.Image(label="Generated Image", visible=False)
|
93 |
-
temperature = gr.Slider(label="Temperature", minimum=0.1, maximum=1.0, value=0.7, step=0.1)
|
94 |
-
max_tokens = gr.Slider(label="Max Tokens", minimum=10, maximum=512, value=100, step=10)
|
95 |
-
top_p = gr.Slider(label="Top-p", minimum=0.1, maximum=1.0, value=0.9, step=0.1)
|
96 |
-
repetition_penalty = gr.Slider(label="Repetition Penalty", minimum=1.0, maximum=2.0, value=1.2, step=0.1)
|
97 |
-
chat_button = gr.Button("Send")
|
98 |
-
|
99 |
-
def respond(user_input, temperature, max_tokens, top_p, repetition_penalty, chat_history=[]):
|
100 |
-
for response, image in generate_response(user_input, chat_history, temperature, max_tokens, top_p, repetition_penalty):
|
101 |
-
if image:
|
102 |
-
return "", image, gr.update(visible=True)
|
103 |
-
return response, None, gr.update(visible=False)
|
104 |
|
105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
demo.launch()
|
|
|
44 |
output += response.token.text
|
45 |
yield output, None
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
with gr.Blocks(theme="Nymbo/Alyx_Theme") as demo:
|
48 |
gr.Markdown("# Chatbot with Image Generation")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
+
with gr.Row():
|
51 |
+
with gr.Column(scale=3):
|
52 |
+
chat_history = gr.Chatbot()
|
53 |
+
chat_input = gr.Textbox(label="User Input", placeholder="Type your message here...")
|
54 |
+
chat_output = gr.Textbox(label="Chatbot Response")
|
55 |
+
image_output = gr.Image(label="Generated Image", visible=False)
|
56 |
+
with gr.Column(scale=1):
|
57 |
+
temperature = gr.Slider(label="Temperature", minimum=0.1, maximum=1.0, value=0.7, step=0.1)
|
58 |
+
max_tokens = gr.Slider(label="Max Tokens", minimum=10, maximum=512, value=100, step=10)
|
59 |
+
top_p = gr.Slider(label="Top-p", minimum=0.1, maximum=1.0, value=0.9, step=0.1)
|
60 |
+
repetition_penalty = gr.Slider(label="Repetition Penalty", minimum=1.0, maximum=2.0, value=1.2, step=0.1)
|
61 |
+
chat_button = gr.Button("Send")
|
62 |
+
|
63 |
+
def respond(user_input, temperature, max_tokens, top_p, repetition_penalty, chat_history=[]):
|
64 |
+
for response, image in generate_response(user_input, chat_history, temperature, max_tokens, top_p, repetition_penalty):
|
65 |
+
if image:
|
66 |
+
return "", image, gr.update(visible=True)
|
67 |
+
return response, None, gr.update(visible=False)
|
68 |
+
|
69 |
+
chat_button.click(respond, inputs=[chat_input, temperature, max_tokens, top_p, repetition_penalty], outputs=[chat_output, image_output, image_output])
|
70 |
|
71 |
demo.launch()
|