File size: 1,949 Bytes
09cb466
599d7c0
5305e57
599d7c0
 
 
5305e57
 
 
 
 
599d7c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import openai
import os
openai.api_key = userdata.get('OPENAI_API_KEY')
# Initialize the OpenAI client
from openai import OpenAI
# HF
API_KEY = os.getenv("OPENAI_API_KEY")
client = OpenAI(api_key=API_KEY)


from datetime import datetime
# gpt function
def chatgpt(prompt):
    today_day = datetime.now().strftime("%Y-%m-%d %H:%M:%S")  # Get current date and time
    response = openai.chat.completions.create(
        model="gpt-4.5-preview-2025-02-27",  # Use an actual available model
        messages=[
            {"role": "system", "content": f"You are GPT 4.5 the latest model from OpenAI, released Feb, 27th 2025 at 3 pm ET. Todays date is: {today_day}"},
            {"role": "user", "content": prompt}
        ]
    )
    return response.choices[0].message.content
#Gradio
import gradio as gr

# Function to handle chat interaction
def respond(message, chat_history):
    bot_message = chatgpt(message)  # Assuming chatgpt is defined elsewhere
    chat_history.append((message, bot_message))
    return "", chat_history

# Create a Gradio Blocks interface
with gr.Blocks(theme=gr.themes.Soft()) as demo:
    gr.Markdown("# Chat with GPT-4.5")
    gr.Markdown("Ask anything to gpt-4.5-preview-2025-02-27 model")
    
    chatbot = gr.Chatbot()
    with gr.Row():
        msg = gr.Textbox(placeholder="Type your message here...", scale=4)
        send = gr.Button("Send", scale=1)
    clear = gr.Button("Clear")
    
    # Set up interactions
    send.click(respond, [msg, chatbot], [msg, chatbot])
    msg.submit(respond, [msg, chatbot], [msg, chatbot])  # Keeps Enter key functionality
    clear.click(lambda: None, None, chatbot, queue=False)
    
    # Add example prompts
    gr.Examples(
        examples=["Tell me about quantum computing", 
                 "Write a short poem about AI",
                 "How can I improve my Python skills?"],
        inputs=msg
    )

# Launch the app
if __name__ == "__main__":
    demo.launch()