paulmondon commited on
Commit
8c57d77
1 Parent(s): 5736862

Add application file

Browse files
Files changed (1) hide show
  1. app.py +14 -47
app.py CHANGED
@@ -1,49 +1,16 @@
1
- !pip install scikit-learn
2
- import pandas as pd
3
- from sklearn.preprocessing import StandardScaler
4
- from sklearn.ensemble import RandomForestClassifier
5
  import gradio as gr
6
- import numpy as np
7
 
8
- # Generate random sensor data
9
- np.random.seed(42)
10
- data = pd.DataFrame({
11
- "Temperature": np.random.randint(0, 100, 100),
12
- "Humidity": np.random.randint(0, 100, 100),
13
- "Pressure": np.random.randint(0, 100, 100),
14
- "Vibration": np.random.randint(0, 100, 100),
15
- "Alert": np.random.randint(0, 2, 100)
16
- })
17
-
18
- # Split the data into features and target
19
- X = data.drop(columns=["Alert"])
20
- y = data["Alert"]
21
-
22
- # Scale the features using the StandardScaler
23
- scaler = StandardScaler()
24
- X_scaled = scaler.fit_transform(X)
25
-
26
- # Train a random forest classifier on the scaled data
27
- clf = RandomForestClassifier(random_state=42)
28
- clf.fit(X_scaled, y)
29
-
30
- # Define the input and output components for Gradio
31
- input_components = [
32
- gr.inputs.Slider(minimum=0, maximum=100, default=50, label="Temperature"),
33
- gr.inputs.Slider(minimum=0, maximum=100, default=50, label="Humidity"),
34
- gr.inputs.Slider(minimum=0, maximum=100, default=50, label="Pressure"),
35
- gr.inputs.Slider(minimum=0, maximum=100, default=50, label="Vibration"),
36
- ]
37
-
38
- output_component = gr.outputs.Textbox(label="Alert")
39
-
40
- # Define the predict function to make the prediction using the model
41
- def predict(temp, humidity, pressure, vibration):
42
- input_data = [[temp, humidity, pressure, vibration]]
43
- input_data_scaled = scaler.transform(input_data)
44
- prediction = clf.predict(input_data_scaled)[0]
45
- return "Alert!" if prediction == 1 else "No alert"
46
-
47
- # Create the Gradio interface and run the app
48
- interface = gr.Interface(predict, inputs=input_components, outputs=output_component, title="5G IoT Alert System")
49
- interface.launch()
 
 
 
 
 
1
  import gradio as gr
 
2
 
3
+ def walking_assistant(voice_command):
4
+ if voice_command.lower() == 'stop':
5
+ return "Stopping"
6
+ elif voice_command.lower() == 'forward':
7
+ return "Moving Forward"
8
+ elif voice_command.lower() == 'left':
9
+ return "Turning Left"
10
+ elif voice_command.lower() == 'right':
11
+ return "Turning Right"
12
+ else:
13
+ return "Invalid Command"
14
+
15
+ iface = gr.Interface(fn=walking_assistant, inputs="text", outputs="text", title="Walking Assistant for the Visually Impaired")
16
+ iface.launch()