shivmeev commited on
Commit
25bc236
·
verified ·
1 Parent(s): 200c9d3

Upload demo.py

Browse files
Files changed (1) hide show
  1. demo.py +41 -0
demo.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import numpy as np
3
+ import torch
4
+ import torch.nn as nn
5
+ import gradio as gr
6
+
7
+ model = nn.Sequential(
8
+ nn.Linear(11, 20),
9
+ nn.ReLU(),
10
+ nn.Linear(20, 5, bias=True))
11
+
12
+ PATH = "wine_model.pth"
13
+
14
+ model.load_state_dict(torch.load(PATH, weights_only=False))
15
+
16
+ def forward(model, input):
17
+ preds = model(input)
18
+ predicted_class = torch.argmax(preds, dim=-1) + 4
19
+ return predicted_class
20
+
21
+ with gr.Blocks() as demo:
22
+ gr.Markdown("Enter your wine data below:")
23
+ input_df = gr.Dataframe(
24
+ row_count=(2, "dynamic"), # Allows adding/removing rows
25
+ col_count=(11, "dynamic"), # Allows adding/removing columns
26
+ headers=list(df.columns)[:-1],
27
+ label="Input Data",
28
+ interactive=True,
29
+ type="pandas" # Specify the desired input type for your function
30
+ )
31
+ output_text = gr.Textbox(label="Processed Output")
32
+
33
+ def process_data(input_dataframe):
34
+ # Perform operations on the input_dataframe
35
+ if isinstance(input_dataframe, pd.DataFrame):
36
+ return forward(model, input_dataframe)
37
+ return "Invalid input type"
38
+
39
+ input_df.change(fn=process_data, inputs=input_df, outputs=output_text)
40
+
41
+ demo.launch()