Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -70,58 +70,27 @@ def generate_text(message, history):
|
|
70 |
history = ["init", input_prompt]
|
71 |
|
72 |
|
73 |
-
#
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
partial_text = ""
|
97 |
-
for i, token in enumerate(generator):
|
98 |
-
if token == model.token_eos() or (max_new_tokens is not None and i >= max_new_tokens):
|
99 |
-
break
|
100 |
-
partial_text += model.detokenize([token]).decode("utf-8", "ignore")
|
101 |
-
history[-1][1] = partial_text
|
102 |
-
return history
|
103 |
-
|
104 |
-
# Gradio UI
|
105 |
-
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
106 |
-
favicon = '<img src="https://cdn-uploads.huggingface.co/production/uploads/64740cf7485a7c8e1bd51ac9/seIR5ErFdX5Snr4O7r7tY.png" width="68px" style="display: inline">'
|
107 |
-
gr.Markdown(f"""<h1><center>{favicon}A N I M A</center></h1>ANIMA is an expert in various scientific disciplines.""")
|
108 |
-
with gr.Row():
|
109 |
-
with gr.Column(scale=5):
|
110 |
-
|
111 |
-
chatbot = gr.Chatbot(label="Dialogue").style(height=400)
|
112 |
-
with gr.Row():
|
113 |
-
with gr.Column():
|
114 |
-
msg = gr.Textbox(label="Send Message", placeholder="Send Message", show_label=False).style(container=False)
|
115 |
-
with gr.Column():
|
116 |
-
with gr.Row():
|
117 |
-
submit = gr.Button("Send")
|
118 |
-
stop = gr.Button("Stop")
|
119 |
-
clear = gr.Button("Clear")
|
120 |
-
with gr.Row():
|
121 |
-
gr.Markdown("""WARNING: The model may generate factually or ethically incorrect texts. We are not responsible for this.""")
|
122 |
-
|
123 |
-
submit_event = msg.submit(fn=user, inputs=[msg, chatbot], outputs=[msg, chatbot], queue=False).success(fn=bot, inputs=[chatbot, system_prompt], outputs=chatbot, queue=True)
|
124 |
-
submit_click_event = submit.click(fn=user, inputs=[msg, chatbot], outputs=[msg, chatbot], queue=False).success(fn=bot, inputs=[chatbot, system_prompt], outputs=chatbot, queue=True)
|
125 |
-
stop.click(fn=None, inputs=None, outputs=None, cancels=[submit_event, submit_click_event], queue=False)
|
126 |
-
clear.click(lambda: None, None, chatbot, queue=False)
|
127 |
demo.launch(max_threads=10)
|
|
|
70 |
history = ["init", input_prompt]
|
71 |
|
72 |
|
73 |
+
# Initialize Gradio Chat Interface
|
74 |
+
demo = gr.ChatInterface(
|
75 |
+
fn=generate_text,
|
76 |
+
title="ANIMA: Biomimicry Exploration",
|
77 |
+
description="Dive into the scientific and philosophical aspects of biomimicry, and discover nature-inspired innovations with ANIMA.",
|
78 |
+
examples=[
|
79 |
+
"How do animals adapt to extreme environments?",
|
80 |
+
"What are some examples of biomimicry in architecture?",
|
81 |
+
"Explain the concept of bio-inspired materials"
|
82 |
+
],
|
83 |
+
cache_examples=True,
|
84 |
+
show_tips=True,
|
85 |
+
theme="h2o",
|
86 |
+
allow_flagging="never",
|
87 |
+
placeholder="Ask me about biomimicry, nature's strategies, and more...",
|
88 |
+
undo_btn="Delete Previous",
|
89 |
+
clear_btn="Start Over",
|
90 |
+
max_thread_length=6,
|
91 |
+
show_timestamp=True,
|
92 |
+
allow_screenshot=False,
|
93 |
+
enable_queue=True,
|
94 |
+
css=css # Apply custom CSS
|
95 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
demo.launch(max_threads=10)
|