hadadrjt commited on
Commit
44d7fd8
·
1 Parent(s): 46f6cf1

gpt-4.1-nano: Guard with blocks.

Browse files
Files changed (1) hide show
  1. app.py +61 -35
app.py CHANGED
@@ -7,38 +7,64 @@ import os # Used for accessing environment variables
7
  import gradio as gr # Used to create the user interface
8
 
9
  # Gradio user interface
10
- gr.load_chat(
11
- os.getenv("OPENAI_API_BASE_URL"), # Endpoint
12
- token=os.getenv("OPENAI_API_KEY"), # API Key
13
- model="gpt-4.1-nano", # Model
14
- description="""
15
- <b>Demo only! <a href="https://umint-openwebui.hf.space"
16
- target="_blank">Click here</a> to continue.
17
- Please read the
18
- <a href="https://huggingface.co/spaces/umint/ai/discussions"
19
- target="_blank">discussions</a> before you go.
20
- Like this project? Feel free to buy me a
21
- <a href="https://ko-fi.com/hadad" target="_blank">
22
- coffee</a></b>.
23
- """, # Project description
24
- chatbot=gr.Chatbot(
25
- label="ChatGPT | GPT-4.1 (Nano)", # Chatbot title
26
- type="messages", # OpenAI-style messages format
27
- show_copy_button=True, # Allow users to copy responses
28
- scale=1 # Standard display scaling
29
- ),
30
- file_types=["image"], # Multimodal
31
- examples=[
32
- ["Please introduce yourself."],
33
- [{"text": "Explain about this image.",
34
- "files": ["assets/images/9299765.jpg"]}],
35
- ["Give me a short introduction to large language model."],
36
- ["Explain about quantum computers."]
37
- ], # Provide sample inputs for users to try
38
- cache_examples=False, # Ensure responses always fresh
39
- show_api=False, # Disable Gradio API
40
- fill_width=True # Auto width, adjust to the monitor screen
41
- ).launch(
42
- max_file_size="1mb", # Max image upload size limit
43
- server_name="0.0.0.0" # Listen on all network interfaces
44
- ) # Start the app
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  import gradio as gr # Used to create the user interface
8
 
9
  # Gradio user interface
10
+ with gr.Blocks(
11
+ fill_height=True, # Adjusting to the height of the user's screen
12
+ fill_width=True # Adjusting to the width of the user's screen
13
+ ) as app:
14
+ # Sidebar
15
+ with gr.Sidebar():
16
+ # Project description
17
+ gr.HTML(
18
+ """
19
+ <b>Demo only! <a href="https://umint-openwebui.hf.space"
20
+ target="_blank">Click here</a> to continue.</b>
21
+ <br><br>Please read the <b><a href=
22
+ "https://huggingface.co/spaces/umint/ai/discussions"
23
+ target="_blank">discussions</a></b> before you go.
24
+ <br><br>In this demo, only <b>image</b>
25
+ upload are allowed. The maximum file size for an
26
+ image upload is <b>1MB</b>.
27
+ <b>The system will automatically reject any file that
28
+ exceeds this limit.</b><br><br>
29
+ It is also not permitted to input prohibited content.
30
+ <b>The system will automatically return an error if an
31
+ attempt is made.</b><br><br>
32
+ Please read the <b><a href=
33
+ "https://huggingface.co/spaces/umint/ai/discussions/37"
34
+ target="_blank">Terms of Service</a></b>
35
+ before deciding to move on to the more advanced
36
+ version.<br><br> <b>Like this project?
37
+ Feel free to buy me a <a href=
38
+ "https://ko-fi.com/hadad"
39
+ target="_blank">coffee</a></b>.
40
+ """
41
+ )
42
+ # Load chat interface
43
+ gr.load_chat(
44
+ os.getenv("OPENAI_API_BASE_URL"), # Endpoint
45
+ token=os.getenv("OPENAI_API_KEY"), # API Key
46
+ model="gpt-4.1-nano", # Model
47
+ chatbot=gr.Chatbot(
48
+ label="ChatGPT | GPT-4.1 (Nano)", # Chatbot title
49
+ type="messages", # OpenAI-style messages format
50
+ show_copy_button=True, # Allow users to copy responses
51
+ scale=1 # Standard display scaling
52
+ ),
53
+ file_types=["image"], # Multimodal
54
+ examples=[
55
+ ["Please introduce yourself."],
56
+ [{"text": "Explain about this image.",
57
+ "files": ["assets/images/9299765.jpg"]}],
58
+ ["Give me a short introduction to large language model."],
59
+ ["Explain about quantum computers."]
60
+ ], # Provide sample inputs for users to try
61
+ cache_examples=False, # Ensure responses always fresh
62
+ show_api=False # Disable Gradio API
63
+ )
64
+
65
+ # Start the app
66
+ app.launch(
67
+ max_file_size="1mb", # Max image upload size limit
68
+ server_name="0.0.0.0", # Listen on all network interfaces
69
+ pwa=True # Progressive Web App
70
+ )