theguywhosucks commited on
Commit
164107f
Β·
verified Β·
1 Parent(s): cd775cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -100
app.py CHANGED
@@ -10,42 +10,7 @@ if not HF_TOKEN:
10
  # Initialize the client for the Coldet backend with HF_TOKEN in headers
11
  coldet_client = Client("Coldet/backend", headers={"Authorization": f"Bearer {HF_TOKEN}"})
12
 
13
- # --- Helper Functions ---
14
-
15
- def create_account(username: str, password: str) -> str:
16
- """Create a new account and return the session ID."""
17
- try:
18
- result = coldet_client.predict(
19
- username=username,
20
- password=password,
21
- api_name="/create_account",
22
- )
23
- return f"Account created! Session ID: {result}"
24
- except Exception as e:
25
- return f"Error: {str(e)}"
26
-
27
- def login(username: str, password: str) -> str:
28
- """Login and return the session ID."""
29
- try:
30
- result = coldet_client.predict(
31
- username=username,
32
- password=password,
33
- api_name="/login",
34
- )
35
- return f"Logged in! Session ID: {result}"
36
- except Exception as e:
37
- return f"Error: {str(e)}"
38
-
39
- def create_token(session_id: str) -> str:
40
- """Generate an API key for the session."""
41
- try:
42
- result = coldet_client.predict(
43
- session_id=session_id,
44
- api_name="/create_token",
45
- )
46
- return f"API Key: {result}"
47
- except Exception as e:
48
- return f"Error: {str(e)}"
49
 
50
  def predict(image, api_key: str, model: str = "coldet-v1-mini.coldet") -> str:
51
  """Run inference on the provided image."""
@@ -62,70 +27,28 @@ def predict(image, api_key: str, model: str = "coldet-v1-mini.coldet") -> str:
62
 
63
  # --- Gradio Interface ---
64
 
65
- with gr.Blocks(title="Coldet Backend Interface", theme=gr.themes.Soft()) as demo:
66
- gr.Markdown("# πŸš€ Coldet Backend Interface")
67
- gr.Markdown("Use this interface to interact with the Coldet backend API.")
68
-
69
- # --- Account Tab ---
70
- with gr.Tab("πŸ”‘ Account"):
71
- gr.Markdown("### Create Account or Login")
72
- with gr.Row():
73
- with gr.Column():
74
- gr.Markdown("#### Create Account")
75
- create_username = gr.Textbox(label="Username", placeholder="Enter username")
76
- create_password = gr.Textbox(label="Password", placeholder="Enter password", type="password")
77
- create_btn = gr.Button("Create Account")
78
- create_output = gr.Textbox(label="Session ID", interactive=False)
79
- create_btn.click(
80
- fn=create_account,
81
- inputs=[create_username, create_password],
82
- outputs=create_output,
83
- )
84
-
85
- with gr.Column():
86
- gr.Markdown("#### Login")
87
- login_username = gr.Textbox(label="Username", placeholder="Enter username")
88
- login_password = gr.Textbox(label="Password", placeholder="Enter password", type="password")
89
- login_btn = gr.Button("Login")
90
- login_output = gr.Textbox(label="Session ID", interactive=False)
91
- login_btn.click(
92
- fn=login,
93
- inputs=[login_username, login_password],
94
- outputs=login_output,
95
- )
96
-
97
- # --- API Key Tab ---
98
- with gr.Tab("πŸ” API Key"):
99
- gr.Markdown("### Generate API Key")
100
- session_id_input = gr.Textbox(label="Session ID", placeholder="Paste your session ID here")
101
- token_btn = gr.Button("Generate API Key")
102
- token_output = gr.Textbox(label="API Key", interactive=False)
103
- token_btn.click(
104
- fn=create_token,
105
- inputs=session_id_input,
106
- outputs=token_output,
107
- )
108
-
109
- # --- Inference Tab ---
110
- with gr.Tab("πŸ€– Inference"):
111
- gr.Markdown("### Run Inference")
112
- with gr.Row():
113
- with gr.Column():
114
- image_input = gr.Image(label="Upload Image", type="filepath")
115
- api_key_input = gr.Textbox(label="API Key", placeholder="Paste your API key here")
116
- model_input = gr.Dropdown(
117
- label="Model",
118
- choices=["coldet-v1-mini.coldet"],
119
- value="coldet-v1-mini.coldet",
120
- )
121
- predict_btn = gr.Button("Run Inference")
122
- with gr.Column():
123
- predict_output = gr.JSON(label="Inference Result")
124
- predict_btn.click(
125
- fn=predict,
126
- inputs=[image_input, api_key_input, model_input],
127
- outputs=predict_output,
128
- )
129
 
130
  # Launch the app
131
  if __name__ == "__main__":
 
10
  # Initialize the client for the Coldet backend with HF_TOKEN in headers
11
  coldet_client = Client("Coldet/backend", headers={"Authorization": f"Bearer {HF_TOKEN}"})
12
 
13
+ # --- Inference Function ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  def predict(image, api_key: str, model: str = "coldet-v1-mini.coldet") -> str:
16
  """Run inference on the provided image."""
 
27
 
28
  # --- Gradio Interface ---
29
 
30
+ with gr.Blocks(title="Coldet Inference", theme=gr.themes.Soft()) as demo:
31
+ gr.Markdown("# πŸ€– Coldet Inference")
32
+ gr.Markdown("Upload an image and paste your API key to run inference.")
33
+
34
+ with gr.Row():
35
+ with gr.Column():
36
+ image_input = gr.Image(label="Upload Image", type="filepath")
37
+ api_key_input = gr.Textbox(label="API Key", placeholder="Paste your API key here")
38
+ model_input = gr.Dropdown(
39
+ label="Model",
40
+ choices=["coldet-v1-mini.coldet"],
41
+ value="coldet-v1-mini.coldet",
42
+ )
43
+ predict_btn = gr.Button("Run Inference", variant="primary")
44
+ with gr.Column():
45
+ predict_output = gr.JSON(label="Inference Result")
46
+
47
+ predict_btn.click(
48
+ fn=predict,
49
+ inputs=[image_input, api_key_input, model_input],
50
+ outputs=predict_output,
51
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
  # Launch the app
54
  if __name__ == "__main__":