ilaydabeyhan commited on
Commit
8ea1126
·
verified ·
1 Parent(s): 2e9cff7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -74
app.py CHANGED
@@ -2,82 +2,28 @@ import gradio as gr
2
  import joblib
3
  import pandas as pd
4
 
5
- # Model ve scaler yükleniyor
6
  model = joblib.load("xgb_model.pkl")
7
  scaler = joblib.load("scaler.pkl")
8
 
9
- # Durum için global değişken kullanabiliriz (ya da gr.State)
10
- class ChatState:
11
- def __init__(self):
12
- self.inputs = []
13
- self.step = 0 # Hangi parametrede olduğumuzu tutar
 
14
 
15
- state = ChatState()
 
 
 
 
 
 
 
 
 
 
16
 
17
- def respond(user_message, chat_history):
18
- global state
19
-
20
- if state.step == 0:
21
- chat_history.append(("assistant", "Lütfen Pressure (kPa) değerini giriniz:"))
22
- state.step = 1
23
- return chat_history, ""
24
-
25
- elif state.step == 1:
26
- try:
27
- pressure = float(user_message)
28
- state.inputs.append(pressure)
29
- chat_history.append(("user", user_message))
30
- chat_history.append(("assistant", "Lütfen Temperature x Pressure değerini giriniz:"))
31
- state.step = 2
32
- return chat_history, ""
33
- except:
34
- chat_history.append(("assistant", "Geçerli bir sayı giriniz lütfen!"))
35
- return chat_history, ""
36
-
37
- elif state.step == 2:
38
- try:
39
- temp_x_pressure = float(user_message)
40
- state.inputs.append(temp_x_pressure)
41
- chat_history.append(("user", user_message))
42
- chat_history.append(("assistant", "Lütfen Material Fusion Metric değerini giriniz:"))
43
- state.step = 3
44
- return chat_history, ""
45
- except:
46
- chat_history.append(("assistant", "Geçerli bir sayı giriniz lütfen!"))
47
- return chat_history, ""
48
-
49
- elif state.step == 3:
50
- try:
51
- fusion_metric = float(user_message)
52
- state.inputs.append(fusion_metric)
53
- chat_history.append(("user", user_message))
54
-
55
- # Tahmin yap
56
- input_df = pd.DataFrame([state.inputs], columns=["Pressure (kPa)", "Temperature x Pressure", "Material Fusion Metric"])
57
- scaled_data = scaler.transform(input_df)
58
- prediction = model.predict(scaled_data)[0]
59
-
60
- msg = f"🔍 Tahmin Edilen Kalite Skoru: {prediction:.2f}"
61
- if prediction < 99:
62
- msg += "\n⚠️ Uyarı: Kalite oranı 99'dan düşük!"
63
-
64
- chat_history.append(("assistant", msg))
65
-
66
- # Resetle
67
- state.inputs = []
68
- state.step = 0
69
-
70
- # Sonraki tur için soruyu tekrar başlat
71
- chat_history.append(("assistant", "Yeniden başlamak için herhangi bir mesaj yazabilirsiniz."))
72
- return chat_history, ""
73
- except:
74
- chat_history.append(("assistant", "Geçerli bir sayı giriniz lütfen!"))
75
- return chat_history, ""
76
-
77
- with gr.Blocks() as demo:
78
- chatbot = gr.Chatbot()
79
- state_text = gr.Textbox(visible=False)
80
- user_input = gr.Textbox(placeholder="Mesajınızı yazın ve Enter'a basın...")
81
- user_input.submit(respond, inputs=[user_input, chatbot], outputs=[chatbot, user_input])
82
-
83
- demo.launch()
 
2
  import joblib
3
  import pandas as pd
4
 
5
+ # Model ve scaler yükle
6
  model = joblib.load("xgb_model.pkl")
7
  scaler = joblib.load("scaler.pkl")
8
 
9
+ def predict_quality(pressure, temp_x_pressure, fusion_metric):
10
+ input_df = pd.DataFrame([[pressure, temp_x_pressure, fusion_metric]],
11
+ columns=["Pressure (kPa)", "Temperature x Pressure", "Material Fusion Metric"])
12
+ scaled = scaler.transform(input_df)
13
+ prediction = model.predict(scaled)[0]
14
+ return float(prediction)
15
 
16
+ iface = gr.Interface(
17
+ fn=predict_quality,
18
+ inputs=[
19
+ gr.Number(label="Pressure (kPa)"),
20
+ gr.Number(label="Temperature x Pressure"),
21
+ gr.Number(label="Material Fusion Metric")
22
+ ],
23
+ outputs=gr.Number(label="Kalite Skoru"),
24
+ title="Kalite Skoru Tahmin Modeli",
25
+ description="Pressure, Temperature x Pressure ve Material Fusion Metric değerlerini giriniz, kalite skorunu tahmin eder."
26
+ )
27
 
28
+ if __name__ == "__main__":
29
+ iface.launch()