Tycohs commited on
Commit
b20d596
·
1 Parent(s): 8b9dc5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -50
app.py CHANGED
@@ -1,57 +1,31 @@
1
- import gradio as gr
2
- import openai
3
- import random
4
- import time
5
- import os
6
 
7
- # Set up OpenAI API key
8
- openai.api_key = os.getenv('APICode2')
9
- system_message = {"role": "system", "content": "You are a helpful assistant."}
 
10
 
11
- with gr.Blocks() as demo:
12
- with gr.Row():
13
- with gr.Column():
14
- msg = gr.Textbox()
15
- btn = gr.Button(value="send")
16
- with gr.Row():
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
- def user(user_message, history):
24
- return "", history + [[user_message, None]]
25
 
26
- def bot(history, messages_history):
27
- user_message = history[-1][0]
28
- bot_message, messages_history = ask_gpt(user_message, messages_history)
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
- def ask_gpt(message, messages_history):
35
- messages_history += [{"role": "user", "content": message}]
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
- def init_history(messages_history):
43
- messages_history = []
44
- messages_history += [system_message]
45
- return messages_history
46
 
47
- def printscr(chatbot):
48
- print("\n\nYour chat hiatory:\n")
49
- for i in range(len(chatbot)):
50
- print(f"User input:{chatbot[i][0]}")
51
- print(f"Bot output:{chatbot[i][1]}")
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)