Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,57 +1,31 @@
|
|
| 1 |
-
import
|
| 2 |
-
import openai
|
| 3 |
-
import random
|
| 4 |
-
import time
|
| 5 |
-
import os
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
chatbot = gr.Chatbot()
|
| 18 |
-
with gr.Row():
|
| 19 |
-
prt = gr.Button("Save in memory")
|
| 20 |
-
clear = gr.Button("Clear")
|
| 21 |
-
state = gr.State([])
|
| 22 |
|
| 23 |
-
|
| 24 |
-
return "", history + [[user_message, None]]
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
messages_history += [{"role": "assistant", "content": bot_message}]
|
| 30 |
-
history[-1][1] = bot_message
|
| 31 |
-
time.sleep(1)
|
| 32 |
-
return history, messages_history
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
response = openai.ChatCompletion.create(
|
| 37 |
-
model="gpt-4",
|
| 38 |
-
messages=messages_history
|
| 39 |
-
)
|
| 40 |
-
return response['choices'][0]['message']['content'], messages_history
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
messages_history += [system_message]
|
| 45 |
-
return messages_history
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
btn.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(bot, [chatbot, state], [chatbot, state])
|
| 54 |
-
prt.click(printscr, chatbot, None)
|
| 55 |
-
clear.click(lambda: None, None, chatbot, queue=False).success(init_history, [state], [state])
|
| 56 |
-
|
| 57 |
-
demo.launch()
|
|
|
|
| 1 |
+
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
# Define the criteria, alternatives, and weights
|
| 4 |
+
criteria = ['Cost', 'Quality', 'Delivery Time']
|
| 5 |
+
alternatives = ['Option A', 'Option B', 'Option C']
|
| 6 |
+
weights = [0.5, 0.3, 0.2]
|
| 7 |
|
| 8 |
+
# Create a DataFrame to hold the evaluation scores
|
| 9 |
+
evaluation_scores = [
|
| 10 |
+
[7, 9, 5],
|
| 11 |
+
[8, 7, 6],
|
| 12 |
+
[6, 8, 7]
|
| 13 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
decision_matrix = pd.DataFrame(evaluation_scores, columns=criteria, index=alternatives)
|
|
|
|
| 16 |
|
| 17 |
+
# Normalize and weight the scores
|
| 18 |
+
normalized_scores = decision_matrix / decision_matrix.max()
|
| 19 |
+
weighted_scores = normalized_scores * weights
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
# Calculate the total score for each alternative
|
| 22 |
+
total_scores = weighted_scores.sum(axis=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
# Determine the best alternative
|
| 25 |
+
best_alternative = total_scores.idxmax()
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
print("Decision Matrix:\n", decision_matrix)
|
| 28 |
+
print("\nNormalized Scores:\n", normalized_scores)
|
| 29 |
+
print("\nWeighted Scores:\n", weighted_scores)
|
| 30 |
+
print("\nTotal Scores:\n", total_scores)
|
| 31 |
+
print("\nBest Alternative:", best_alternative)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|