Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -140,7 +140,7 @@ def generate_response(user_input: str, temperature: float = 0.7, max_tokens: int
|
|
| 140 |
|
| 141 |
|
| 142 |
def chat_fn(user_input, history, temperature, max_tokens):
|
| 143 |
-
"""Chat function for Gradio"""
|
| 144 |
if not user_input or not user_input.strip():
|
| 145 |
return "", history or []
|
| 146 |
|
|
@@ -149,7 +149,11 @@ def chat_fn(user_input, history, temperature, max_tokens):
|
|
| 149 |
if history is None:
|
| 150 |
history = []
|
| 151 |
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
return "", history
|
| 155 |
|
|
@@ -157,14 +161,14 @@ def chat_fn(user_input, history, temperature, max_tokens):
|
|
| 157 |
def feedback_good():
|
| 158 |
if current_conv_id > 0:
|
| 159 |
db.update_feedback(current_conv_id, 1)
|
| 160 |
-
return "Thanks for the positive feedback!"
|
| 161 |
return "No conversation to rate yet."
|
| 162 |
|
| 163 |
|
| 164 |
def feedback_bad():
|
| 165 |
if current_conv_id > 0:
|
| 166 |
db.update_feedback(current_conv_id, -1)
|
| 167 |
-
return "Thanks for the feedback. I will try to improve."
|
| 168 |
return "No conversation to rate yet."
|
| 169 |
|
| 170 |
|
|
@@ -195,18 +199,18 @@ def retrain(epochs):
|
|
| 195 |
tokenizer = trainer.tokenizer
|
| 196 |
|
| 197 |
loss = history.history['loss'][-1]
|
| 198 |
-
return f"Training done! Loss: {loss:.4f}, Used {len(good_convs)} conversations"
|
| 199 |
|
| 200 |
|
| 201 |
def get_stats():
|
| 202 |
stats = db.get_stats()
|
| 203 |
-
return f"""## Statistics
|
| 204 |
|
| 205 |
| Metric | Count |
|
| 206 |
|--------|-------|
|
| 207 |
-
| Conversations | {stats['total']} |
|
| 208 |
-
| Positive | {stats['positive']} |
|
| 209 |
-
| Negative | {stats['negative']} |
|
| 210 |
"""
|
| 211 |
|
| 212 |
|
|
@@ -216,7 +220,7 @@ initialize()
|
|
| 216 |
print("Initialization complete!")
|
| 217 |
|
| 218 |
|
| 219 |
-
# Create Gradio interface
|
| 220 |
with gr.Blocks(title="Veda Programming Assistant") as demo:
|
| 221 |
|
| 222 |
gr.Markdown("""
|
|
@@ -228,9 +232,11 @@ with gr.Blocks(title="Veda Programming Assistant") as demo:
|
|
| 228 |
with gr.Tabs():
|
| 229 |
|
| 230 |
with gr.TabItem("π¬ Chat"):
|
|
|
|
| 231 |
chatbot = gr.Chatbot(
|
| 232 |
label="Conversation",
|
| 233 |
-
height=400
|
|
|
|
| 234 |
)
|
| 235 |
|
| 236 |
with gr.Row():
|
|
|
|
| 140 |
|
| 141 |
|
| 142 |
def chat_fn(user_input, history, temperature, max_tokens):
|
| 143 |
+
"""Chat function for Gradio 6.x with messages format"""
|
| 144 |
if not user_input or not user_input.strip():
|
| 145 |
return "", history or []
|
| 146 |
|
|
|
|
| 149 |
if history is None:
|
| 150 |
history = []
|
| 151 |
|
| 152 |
+
# Gradio 6.x requires messages format with 'role' and 'content'
|
| 153 |
+
history = history + [
|
| 154 |
+
{"role": "user", "content": user_input},
|
| 155 |
+
{"role": "assistant", "content": response}
|
| 156 |
+
]
|
| 157 |
|
| 158 |
return "", history
|
| 159 |
|
|
|
|
| 161 |
def feedback_good():
|
| 162 |
if current_conv_id > 0:
|
| 163 |
db.update_feedback(current_conv_id, 1)
|
| 164 |
+
return "π Thanks for the positive feedback!"
|
| 165 |
return "No conversation to rate yet."
|
| 166 |
|
| 167 |
|
| 168 |
def feedback_bad():
|
| 169 |
if current_conv_id > 0:
|
| 170 |
db.update_feedback(current_conv_id, -1)
|
| 171 |
+
return "π Thanks for the feedback. I will try to improve."
|
| 172 |
return "No conversation to rate yet."
|
| 173 |
|
| 174 |
|
|
|
|
| 199 |
tokenizer = trainer.tokenizer
|
| 200 |
|
| 201 |
loss = history.history['loss'][-1]
|
| 202 |
+
return f"β
Training done! Loss: {loss:.4f}, Used {len(good_convs)} conversations"
|
| 203 |
|
| 204 |
|
| 205 |
def get_stats():
|
| 206 |
stats = db.get_stats()
|
| 207 |
+
return f"""## π Statistics
|
| 208 |
|
| 209 |
| Metric | Count |
|
| 210 |
|--------|-------|
|
| 211 |
+
| π¬ Conversations | {stats['total']} |
|
| 212 |
+
| π Positive | {stats['positive']} |
|
| 213 |
+
| π Negative | {stats['negative']} |
|
| 214 |
"""
|
| 215 |
|
| 216 |
|
|
|
|
| 220 |
print("Initialization complete!")
|
| 221 |
|
| 222 |
|
| 223 |
+
# Create Gradio interface for Gradio 6.x
|
| 224 |
with gr.Blocks(title="Veda Programming Assistant") as demo:
|
| 225 |
|
| 226 |
gr.Markdown("""
|
|
|
|
| 232 |
with gr.Tabs():
|
| 233 |
|
| 234 |
with gr.TabItem("π¬ Chat"):
|
| 235 |
+
# Chatbot with messages format for Gradio 6.x
|
| 236 |
chatbot = gr.Chatbot(
|
| 237 |
label="Conversation",
|
| 238 |
+
height=400,
|
| 239 |
+
type="messages"
|
| 240 |
)
|
| 241 |
|
| 242 |
with gr.Row():
|