File size: 2,830 Bytes
5c89c38
 
 
 
 
 
 
 
 
44d7fd8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#
# SPDX-FileCopyrightText: Hadad <[email protected]>
# SPDX-License-Identifier: Apache-2.0
#

import os  # Used for accessing environment variables
import gradio as gr  # Used to create the user interface

# Gradio user interface
with gr.Blocks(
    fill_height=True,  # Adjusting to the height of the user's screen
    fill_width=True  # Adjusting to the width of the user's screen
) as app:
    # Sidebar
    with gr.Sidebar():
        # Project description
        gr.HTML(
            """
            <b>Demo only! <a href="https://umint-openwebui.hf.space"
            target="_blank">Click here</a> to continue.</b>
            <br><br>Please read the <b><a href=
            "https://huggingface.co/spaces/umint/ai/discussions" 
            target="_blank">discussions</a></b> before you go.
            <br><br>In this demo, only <b>image</b>
            upload are allowed. The maximum file size for an 
            image upload is <b>1MB</b>. 
            <b>The system will automatically reject any file that 
            exceeds this limit.</b><br><br>
            It is also not permitted to input prohibited content. 
            <b>The system will automatically return an error if an 
            attempt is made.</b><br><br>
            Please read the <b><a href=
            "https://huggingface.co/spaces/umint/ai/discussions/37" 
            target="_blank">Terms of Service</a></b> 
            before deciding to move on to the more advanced 
            version.<br><br> <b>Like this project? 
            Feel free to buy me a <a href=
            "https://ko-fi.com/hadad" 
            target="_blank">coffee</a></b>.
            """
        )
    # Load chat interface
    gr.load_chat(
        os.getenv("OPENAI_API_BASE_URL"),  # Endpoint
        token=os.getenv("OPENAI_API_KEY"),  # API Key
        model="gpt-4.1-nano",  # Model
        chatbot=gr.Chatbot(
            label="ChatGPT | GPT-4.1 (Nano)",  # Chatbot title
            type="messages",  # OpenAI-style messages format
            show_copy_button=True,  # Allow users to copy responses
            scale=1  # Standard display scaling
        ),
        file_types=["image"],  # Multimodal
        examples=[
            ["Please introduce yourself."],
            [{"text": "Explain about this image.",
              "files": ["assets/images/9299765.jpg"]}],
            ["Give me a short introduction to large language model."],
            ["Explain about quantum computers."]
        ],  # Provide sample inputs for users to try
        cache_examples=False,  # Ensure responses always fresh
        show_api=False  # Disable Gradio API
    )

# Start the app
app.launch(
    max_file_size="1mb",    # Max image upload size limit
    server_name="0.0.0.0",  # Listen on all network interfaces
    pwa=True  # Progressive Web App
)