ravinder2024 commited on
Commit
d2ca3a7
·
verified ·
1 Parent(s): 6c2cdf1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -35
app.py CHANGED
@@ -14,14 +14,14 @@ def setup_database():
14
  CREATE TABLE IF NOT EXISTS students (
15
  id INTEGER PRIMARY KEY AUTOINCREMENT,
16
  name TEXT,
17
- rno INTEGER,
18
  image_path TEXT
19
  )
20
  """)
21
  conn.commit()
22
  conn.close()
23
 
24
- def register_student(name, rno, image_file):
25
  conn = sqlite3.connect(DB_PATH)
26
  cursor = conn.cursor()
27
 
@@ -32,30 +32,11 @@ def register_student(name, rno, image_file):
32
  else:
33
  image_path = None
34
 
35
- cursor.execute("INSERT INTO students (name, rno, image_path) VALUES (?, ?, ?)", (name, rno, image_path))
36
  conn.commit()
37
  conn.close()
38
  return f"Student {name} registered successfully!"
39
 
40
- def view_records():
41
- conn = sqlite3.connect(DB_PATH)
42
- cursor = conn.cursor()
43
- cursor.execute("SELECT name, rno, image_path FROM students")
44
- records = cursor.fetchall()
45
- conn.close()
46
-
47
- if not records:
48
- return "No records found."
49
-
50
- output = []
51
- for name, age, image_path in records:
52
- record = f"Name: {name}, ROLL_NO: {rno}"
53
- if image_path and os.path.exists(image_path):
54
- record += f"\nImage: {image_path}"
55
- output.append(record)
56
-
57
- return "\n\n".join(output)
58
-
59
  # Initialize the database
60
  setup_database()
61
 
@@ -66,27 +47,17 @@ with gr.Blocks() as demo:
66
 
67
  with gr.Row():
68
  name_input = gr.Textbox(label="Name", placeholder="Enter the student's name")
69
- rno_input = gr.Number(label="ROLL_NO", precision=0)
70
  image_input = gr.Image(label="Upload Image", type="filepath")
71
 
72
- with gr.Row():
73
- register_button = gr.Button("Register Student")
74
- record_button = gr.Button("View Records")
75
-
76
  output = gr.Textbox(label="Status")
77
 
78
  register_button.click(
79
  register_student,
80
- inputs=[name_input, rno_input, image_input],
81
  outputs=output,
82
  )
83
 
84
- record_button.click(
85
- view_records,
86
- outputs=output
87
- )
88
-
89
  # Launch the Gradio app
90
  demo.launch()
91
-
92
-
 
14
  CREATE TABLE IF NOT EXISTS students (
15
  id INTEGER PRIMARY KEY AUTOINCREMENT,
16
  name TEXT,
17
+ age INTEGER,
18
  image_path TEXT
19
  )
20
  """)
21
  conn.commit()
22
  conn.close()
23
 
24
+ def register_student(name, age, image_file):
25
  conn = sqlite3.connect(DB_PATH)
26
  cursor = conn.cursor()
27
 
 
32
  else:
33
  image_path = None
34
 
35
+ cursor.execute("INSERT INTO students (name, age, image_path) VALUES (?, ?, ?)", (name, age, image_path))
36
  conn.commit()
37
  conn.close()
38
  return f"Student {name} registered successfully!"
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  # Initialize the database
41
  setup_database()
42
 
 
47
 
48
  with gr.Row():
49
  name_input = gr.Textbox(label="Name", placeholder="Enter the student's name")
50
+ age_input = gr.Number(label="Age", precision=0)
51
  image_input = gr.Image(label="Upload Image", type="filepath")
52
 
53
+ register_button = gr.Button("Register Student")
 
 
 
54
  output = gr.Textbox(label="Status")
55
 
56
  register_button.click(
57
  register_student,
58
+ inputs=[name_input, age_input, image_input],
59
  outputs=output,
60
  )
61
 
 
 
 
 
 
62
  # Launch the Gradio app
63
  demo.launch()