PercyHo commited on
Commit
b5f5cd7
·
verified ·
1 Parent(s): b4f5c21

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -72
app.py CHANGED
@@ -1,76 +1,8 @@
1
- import pandas as pd
2
-
3
- dataset = pd.read_csv('cancer.csv')
4
-
5
- x = dataset.drop(columns=["diagnosis(1=m, 0=b)"])
6
-
7
- y = dataset["diagnosis(1=m, 0=b)"]
8
-
9
- from sklearn.model_selection import train_test_split
10
-
11
- x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)
12
-
13
- import tensorflow as tf
14
-
15
- model = tf.keras.models.Sequential()
16
-
17
- model.add(tf.keras.layers.Dense(256, input_shape=x_train.shape, activation='sigmoid'))
18
- model.add(tf.keras.layers.Dense(256, activation='sigmoid'))
19
- model.add(tf.keras.layers.Dense(1, activation='sigmoid'))
20
-
21
- model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
22
-
23
- model.fit(x_train, y_train, epochs=1000)
24
-
25
- model.evaluate(x_test, y_test)
26
-
27
- model.save("percyAI_model.h5")
28
-
29
- from google.colab import files
30
- files.download("percyAI_model.h5")
31
-
32
- from tensorflow.keras.models import load_model
33
- model = load_model("percyAI_model.h5")
34
-
35
- import numpy as np
36
- import tensorflow as tf
37
- from tensorflow import keras
38
- from tensorflow.keras import layers
39
-
40
- x_values = np.random.randint(0, 100, (10000, 2))
41
- y_values = np.sum(x_values, axis=1)
42
-
43
- x_values = x_values / 100.0
44
- y_values = y_values / 200.0
45
-
46
- model = keras.Sequential([
47
- layers.Dense(64, activation='relu', input_shape=(2,)),
48
- layers.Dense(64, activation='relu'),
49
- layers.Dense(1)
50
- ])
51
-
52
- model.compile(optimizer='adam', loss='mse', metrics=['mae'])
53
-
54
- model.fit(x_values, y_values, epochs=30, batch_size=32, validation_split=0.2)
55
-
56
- test_input = np.array([[25, 30]]) / 100.0
57
- prediction = model.predict(test_input) * 200.0
58
- print("Predicted sum:", prediction[0][0])
59
-
60
- model.save("percyAI_model.h5")
61
-
62
-
63
-
64
- model.save("percyAI_model.h5")
65
-
66
-
67
-
68
  import gradio as gr
69
  import re
70
 
71
  BOT_NAME = "Phu Quy Ho"
72
 
73
- # Basic math evaluator (with safety)
74
  def handle_math(user_input):
75
  user_input = user_input.lower().strip()
76
 
@@ -79,8 +11,8 @@ def handle_math(user_input):
79
  if any(greet in user_input for greet in greetings):
80
  return f"Hello! I am {BOT_NAME}. I can help you with math. Try something like: (3 + 5) * -2"
81
 
82
- # Remove filler words like "what is"
83
- math_expression = re.sub(r"[^\d\.\+\-\*/\(\)\s]", "", user_input) # Strip out words, keep symbols
84
  math_expression = math_expression.replace("what is", "").strip()
85
 
86
  try:
@@ -90,10 +22,12 @@ def handle_math(user_input):
90
  return "Sorry, I couldn't understand that. Please enter a valid math expression like (2 + 3) * -1"
91
 
92
  # Gradio UI
93
- gr.Interface(
94
  fn=handle_math,
95
  inputs="text",
96
  outputs="text",
97
  title="Phu Quy Ho – Smart Math Solver",
98
  description="Say hello or ask me a math question! I support +, -, *, /, negative numbers, and parentheses."
99
- ).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import re
3
 
4
  BOT_NAME = "Phu Quy Ho"
5
 
 
6
  def handle_math(user_input):
7
  user_input = user_input.lower().strip()
8
 
 
11
  if any(greet in user_input for greet in greetings):
12
  return f"Hello! I am {BOT_NAME}. I can help you with math. Try something like: (3 + 5) * -2"
13
 
14
+ # Remove everything except math symbols and numbers
15
+ math_expression = re.sub(r"[^\d\.\+\-\*/\(\)\s]", "", user_input)
16
  math_expression = math_expression.replace("what is", "").strip()
17
 
18
  try:
 
22
  return "Sorry, I couldn't understand that. Please enter a valid math expression like (2 + 3) * -1"
23
 
24
  # Gradio UI
25
+ demo = gr.Interface(
26
  fn=handle_math,
27
  inputs="text",
28
  outputs="text",
29
  title="Phu Quy Ho – Smart Math Solver",
30
  description="Say hello or ask me a math question! I support +, -, *, /, negative numbers, and parentheses."
31
+ )
32
+
33
+ demo.launch()