Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,51 +24,37 @@ def generate_text(prompt, max_length=100, min_length=20, temperature=1.0):
|
|
| 24 |
return generated_text
|
| 25 |
|
| 26 |
with gr.Blocks() as demo:
|
|
|
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
elem_id="chatbot",
|
| 31 |
bubble_full_width=False,
|
| 32 |
-
avatar_images=(None, None),
|
| 33 |
)
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
scale=3,
|
| 41 |
-
show_label=False,
|
| 42 |
-
placeholder="Enter your text prompt here...",
|
| 43 |
-
),
|
| 44 |
-
gr.Slider(0, 2048, 100, label="Max Length"),
|
| 45 |
-
gr.Slider(0, 2048, 20, label="Min Length"),
|
| 46 |
-
gr.Slider(0.1, 2.0, 1.0, label="Temperature"),
|
| 47 |
-
gr.Button("Generate Text"),
|
| 48 |
-
],
|
| 49 |
-
style="min-width:300px",
|
| 50 |
-
)
|
| 51 |
-
|
| 52 |
-
demo.textbox_result = demo.container_result = gr.Textbox(
|
| 53 |
-
value="", label="Generated Text", interactive=False
|
| 54 |
)
|
| 55 |
|
| 56 |
-
def
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
return demo.textbox_result
|
| 60 |
-
|
| 61 |
-
def add_prompt_and_generate(chat_history, prompt):
|
| 62 |
-
chat_history.append(((prompt,), None))
|
| 63 |
-
return generate_and_update(prompt, 100, 20, 1.0)
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
demo.textbox_result,
|
| 68 |
-
scale=3,
|
| 69 |
-
show_label=False,
|
| 70 |
-
placeholder="Type a prompt and press enter...",
|
| 71 |
)
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
if __name__ == "__main__":
|
| 74 |
demo.launch()
|
|
|
|
| 24 |
return generated_text
|
| 25 |
|
| 26 |
with gr.Blocks() as demo:
|
| 27 |
+
chat_history = []
|
| 28 |
|
| 29 |
+
chatbot = gr.Chatbot(
|
| 30 |
+
chat_history,
|
| 31 |
elem_id="chatbot",
|
| 32 |
bubble_full_width=False,
|
| 33 |
+
avatar_images=(None, None), # You can add avatars if needed
|
| 34 |
)
|
| 35 |
|
| 36 |
+
user_input = gr.Textbox(
|
| 37 |
+
scale=4,
|
| 38 |
+
show_label=False,
|
| 39 |
+
placeholder="Type your message and press enter...",
|
| 40 |
+
container=False,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
)
|
| 42 |
|
| 43 |
+
def process_user_input(history, text):
|
| 44 |
+
history.append(("User", text))
|
| 45 |
+
return history, gr.Textbox(value="", interactive=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
user_input_msg = user_input.submit(
|
| 48 |
+
process_user_input, [chat_history, user_input], [chatbot, user_input], queue=False
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
)
|
| 50 |
|
| 51 |
+
def generate_response(history):
|
| 52 |
+
last_user_input = [msg for msg in history if msg[0] == "User"][-1][1]
|
| 53 |
+
generated_response = generate_text(last_user_input)
|
| 54 |
+
history.append(("Chatbot", generated_response))
|
| 55 |
+
return history
|
| 56 |
+
|
| 57 |
+
user_input_msg.then(generate_response, [chat_history], queue=False)
|
| 58 |
+
|
| 59 |
if __name__ == "__main__":
|
| 60 |
demo.launch()
|