Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -92,48 +92,28 @@ def generate_response(model_id, conversation, user_message, max_length=512, temp
|
|
92 |
|
93 |
return response, load_time, generation_time
|
94 |
|
95 |
-
def
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
if conversation is None:
|
100 |
-
conversation = []
|
101 |
|
102 |
# Get model ID
|
103 |
model_id = MODELS.get(model_name, MODELS["Athena-R3X 8B"])
|
104 |
|
105 |
try:
|
106 |
-
# Add user message to conversation
|
107 |
-
conversation.append([user_message, ""])
|
108 |
-
|
109 |
# Generate response using ZeroGPU
|
110 |
response, load_time, generation_time = generate_response(
|
111 |
-
model_id,
|
112 |
)
|
113 |
|
114 |
-
#
|
115 |
-
|
116 |
-
|
117 |
-
stats = f"β‘ Load: {load_time:.1f}s | Gen: {generation_time:.1f}s | Model: {model_name}"
|
118 |
-
|
119 |
-
return conversation, "", stats
|
120 |
|
121 |
except Exception as e:
|
122 |
-
|
123 |
-
if conversation:
|
124 |
-
conversation[-1][1] = error_msg
|
125 |
-
else:
|
126 |
-
conversation = [[user_message, error_msg]]
|
127 |
-
return conversation, "", f"β Error: {str(e)}"
|
128 |
-
|
129 |
-
def clear_chat():
|
130 |
-
return [], "", ""
|
131 |
|
132 |
# CSS for better styling
|
133 |
css = """
|
134 |
-
#chatbot {
|
135 |
-
height: 600px;
|
136 |
-
}
|
137 |
.message {
|
138 |
padding: 10px;
|
139 |
margin: 5px;
|
@@ -143,79 +123,56 @@ css = """
|
|
143 |
|
144 |
theme = gr.themes.Monochrome()
|
145 |
|
146 |
-
# Create
|
147 |
with gr.Blocks(title="Athena Playground Chat", css=css, theme=theme) as demo:
|
148 |
gr.Markdown("# π Athena Playground Chat")
|
149 |
gr.Markdown("*Powered by HuggingFace ZeroGPU*")
|
150 |
|
151 |
-
#
|
152 |
-
chat_history = gr.Chatbot(
|
153 |
-
elem_id="chatbot",
|
154 |
-
show_label=False,
|
155 |
-
show_share_button=False,
|
156 |
-
container=False
|
157 |
-
)
|
158 |
-
|
159 |
-
user_input = gr.Textbox(
|
160 |
-
placeholder="Ask Athena anything...",
|
161 |
-
label="Your message",
|
162 |
-
lines=2,
|
163 |
-
max_lines=10
|
164 |
-
)
|
165 |
-
|
166 |
with gr.Row():
|
167 |
-
|
168 |
-
clear_btn = gr.Button("ποΈ Clear Chat", variant="secondary")
|
169 |
-
|
170 |
-
stats_output = gr.Textbox(
|
171 |
-
label="Stats",
|
172 |
-
interactive=False,
|
173 |
-
show_label=False,
|
174 |
-
placeholder="Stats will appear here..."
|
175 |
-
)
|
176 |
-
|
177 |
-
# Configuration settings at the bottom
|
178 |
-
gr.Markdown("---")
|
179 |
-
gr.Markdown("## βοΈ Configuration")
|
180 |
-
|
181 |
-
with gr.Row():
|
182 |
-
with gr.Column():
|
183 |
model_choice = gr.Dropdown(
|
184 |
label="π± Model",
|
185 |
choices=list(MODELS.keys()),
|
186 |
value="Athena-R3X 8B",
|
187 |
info="Select which Athena model to use"
|
188 |
)
|
189 |
-
with gr.Column():
|
190 |
max_length = gr.Slider(
|
191 |
32, 2048, value=512,
|
192 |
label="π Max Tokens",
|
193 |
info="Maximum number of tokens to generate"
|
194 |
)
|
195 |
-
with gr.Column():
|
196 |
temperature = gr.Slider(
|
197 |
0.1, 2.0, value=0.7,
|
198 |
label="π¨ Creativity",
|
199 |
info="Higher values = more creative responses"
|
200 |
)
|
201 |
|
202 |
-
#
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
)
|
220 |
|
221 |
if __name__ == "__main__":
|
|
|
92 |
|
93 |
return response, load_time, generation_time
|
94 |
|
95 |
+
def respond(message, history, model_name, max_length, temperature):
|
96 |
+
"""Main function for ChatInterface - simplified signature"""
|
97 |
+
if not message.strip():
|
98 |
+
return "Please enter a message"
|
|
|
|
|
99 |
|
100 |
# Get model ID
|
101 |
model_id = MODELS.get(model_name, MODELS["Athena-R3X 8B"])
|
102 |
|
103 |
try:
|
|
|
|
|
|
|
104 |
# Generate response using ZeroGPU
|
105 |
response, load_time, generation_time = generate_response(
|
106 |
+
model_id, history, message, max_length, temperature
|
107 |
)
|
108 |
|
109 |
+
# ChatInterface expects a generator for streaming or just return the response
|
110 |
+
return response
|
|
|
|
|
|
|
|
|
111 |
|
112 |
except Exception as e:
|
113 |
+
return f"Error: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
# CSS for better styling
|
116 |
css = """
|
|
|
|
|
|
|
117 |
.message {
|
118 |
padding: 10px;
|
119 |
margin: 5px;
|
|
|
123 |
|
124 |
theme = gr.themes.Monochrome()
|
125 |
|
126 |
+
# Create ChatInterface
|
127 |
with gr.Blocks(title="Athena Playground Chat", css=css, theme=theme) as demo:
|
128 |
gr.Markdown("# π Athena Playground Chat")
|
129 |
gr.Markdown("*Powered by HuggingFace ZeroGPU*")
|
130 |
|
131 |
+
# Additional inputs for configuration
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
with gr.Row():
|
133 |
+
with gr.Column(scale=1):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
model_choice = gr.Dropdown(
|
135 |
label="π± Model",
|
136 |
choices=list(MODELS.keys()),
|
137 |
value="Athena-R3X 8B",
|
138 |
info="Select which Athena model to use"
|
139 |
)
|
140 |
+
with gr.Column(scale=1):
|
141 |
max_length = gr.Slider(
|
142 |
32, 2048, value=512,
|
143 |
label="π Max Tokens",
|
144 |
info="Maximum number of tokens to generate"
|
145 |
)
|
146 |
+
with gr.Column(scale=1):
|
147 |
temperature = gr.Slider(
|
148 |
0.1, 2.0, value=0.7,
|
149 |
label="π¨ Creativity",
|
150 |
info="Higher values = more creative responses"
|
151 |
)
|
152 |
|
153 |
+
# Create the ChatInterface
|
154 |
+
chat_interface = gr.ChatInterface(
|
155 |
+
fn=respond,
|
156 |
+
additional_inputs=[model_choice, max_length, temperature],
|
157 |
+
title="Chat with Athena",
|
158 |
+
description="Ask Athena anything!",
|
159 |
+
theme="soft",
|
160 |
+
examples=[
|
161 |
+
"Hello! How are you?",
|
162 |
+
"What can you help me with?",
|
163 |
+
"Tell me about artificial intelligence",
|
164 |
+
"Write a short poem about space"
|
165 |
+
],
|
166 |
+
cache_examples=False,
|
167 |
+
retry_btn=None,
|
168 |
+
undo_btn="β©οΈ Undo",
|
169 |
+
clear_btn="ποΈ Clear",
|
170 |
+
submit_btn="π€ Send",
|
171 |
+
chatbot=gr.Chatbot(
|
172 |
+
height=500,
|
173 |
+
placeholder="Start chatting with Athena...",
|
174 |
+
show_share_button=False
|
175 |
+
)
|
176 |
)
|
177 |
|
178 |
if __name__ == "__main__":
|