eBlessings commited on
Commit
c17753d
Β·
verified Β·
1 Parent(s): 145b207

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -15
app.py CHANGED
@@ -1,12 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import secrets
3
 
4
- # A simple in-memory store for valid API keys.
5
- # In production, consider a persistent storage and more robust validation.
6
  valid_api_keys = set()
7
 
8
  def generate_api_key():
9
- """Generate a new secure API key and store it."""
 
 
 
10
  key = secrets.token_hex(16)
11
  valid_api_keys.add(key)
12
  return key
@@ -16,19 +31,19 @@ def llama_vision_inference(api_key, image):
16
  Dummy inference function for Llama Vision model.
17
  Replace the simulated processing below with actual model loading and inference.
18
  """
19
- # Validate the provided API key.
20
  if not api_key.strip():
21
  return "Error: API key is required."
22
  if api_key not in valid_api_keys:
23
  return "Error: Invalid API key. Please generate a valid key first."
24
-
25
- # Here you would load and run your Llama vision model.
26
- # For example:
27
  # from llama_vision import LlamaVisionModel
28
  # model = LlamaVisionModel.from_pretrained("llama-vision-latest")
29
- # result = model.process(image)
30
  #
31
- # In this example, we'll simulate the output:
32
  result = (
33
  "Simulated Model Output:\n"
34
  "- Detected GUI elements: [button, menu, text field]\n"
@@ -37,13 +52,13 @@ def llama_vision_inference(api_key, image):
37
  )
38
  return result
39
 
40
- with gr.Blocks() as demo:
41
- gr.Markdown("# Llama Vision Model API")
42
-
43
- # Use Tabs to separate the API Key Generator from the Vision Model interface.
44
  with gr.Tabs():
45
  with gr.TabItem("API Key Generator"):
46
- gr.Markdown("Generate an API key that can be used with the vision model API.")
47
  key_output = gr.Textbox(label="Your Generated API Key", interactive=False)
48
  generate_button = gr.Button("Generate API Key")
49
  generate_button.click(fn=generate_api_key, outputs=key_output)
@@ -56,4 +71,5 @@ with gr.Blocks() as demo:
56
  run_button = gr.Button("Run Vision Model")
57
  run_button.click(fn=llama_vision_inference, inputs=[api_key_input, image_input], outputs=output_text)
58
 
59
- demo.launch()
 
 
1
+ """
2
+ title: Manus
3
+ emoji: πŸš€
4
+ colorFrom: red
5
+ colorTo: blue
6
+ sdk: gradio
7
+ sdk_version: 5.20.1
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ """
12
+
13
  import gradio as gr
14
  import secrets
15
 
16
+ # In-memory store for valid API keys.
17
+ # For production, consider using a persistent storage solution.
18
  valid_api_keys = set()
19
 
20
  def generate_api_key():
21
+ """
22
+ Generate a secure 32-character hexadecimal API key,
23
+ store it in the valid_api_keys set, and return it.
24
+ """
25
  key = secrets.token_hex(16)
26
  valid_api_keys.add(key)
27
  return key
 
31
  Dummy inference function for Llama Vision model.
32
  Replace the simulated processing below with actual model loading and inference.
33
  """
34
+ # Validate the API key.
35
  if not api_key.strip():
36
  return "Error: API key is required."
37
  if api_key not in valid_api_keys:
38
  return "Error: Invalid API key. Please generate a valid key first."
39
+
40
+ # Here, insert the code to load and run your Llama Vision model.
41
+ # Example (pseudo-code):
42
  # from llama_vision import LlamaVisionModel
43
  # model = LlamaVisionModel.from_pretrained("llama-vision-latest")
44
+ # result = model.infer(image)
45
  #
46
+ # For this example, we simulate the output:
47
  result = (
48
  "Simulated Model Output:\n"
49
  "- Detected GUI elements: [button, menu, text field]\n"
 
52
  )
53
  return result
54
 
55
+ with gr.Blocks(title="Manus πŸš€") as demo:
56
+ gr.Markdown("# Manus πŸš€")
57
+ gr.Markdown("This Gradio Space lets you generate an API key and perform vision inference using the Llama Vision model.")
58
+
59
  with gr.Tabs():
60
  with gr.TabItem("API Key Generator"):
61
+ gr.Markdown("Generate an API key to be used with the vision model API.")
62
  key_output = gr.Textbox(label="Your Generated API Key", interactive=False)
63
  generate_button = gr.Button("Generate API Key")
64
  generate_button.click(fn=generate_api_key, outputs=key_output)
 
71
  run_button = gr.Button("Run Vision Model")
72
  run_button.click(fn=llama_vision_inference, inputs=[api_key_input, image_input], outputs=output_text)
73
 
74
+ if __name__ == "__main__":
75
+ demo.launch()