diegocp01 commited on
Commit
599d7c0
·
1 Parent(s): 3d088ed
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from google.colab import userdata
2
+ import openai
3
+ openai.api_key = userdata.get('OPENAI_API_KEY')
4
+ # Initialize the OpenAI client
5
+ from openai import OpenAI
6
+ client = OpenAI(api_key=openai.api_key)
7
+ from datetime import datetime
8
+ # gpt function
9
+ def chatgpt(prompt):
10
+ today_day = datetime.now().strftime("%Y-%m-%d %H:%M:%S") # Get current date and time
11
+ response = openai.chat.completions.create(
12
+ model="gpt-4.5-preview-2025-02-27", # Use an actual available model
13
+ messages=[
14
+ {"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}"},
15
+ {"role": "user", "content": prompt}
16
+ ]
17
+ )
18
+ return response.choices[0].message.content
19
+ #Gradio
20
+ import gradio as gr
21
+
22
+ # Function to handle chat interaction
23
+ def respond(message, chat_history):
24
+ bot_message = chatgpt(message) # Assuming chatgpt is defined elsewhere
25
+ chat_history.append((message, bot_message))
26
+ return "", chat_history
27
+
28
+ # Create a Gradio Blocks interface
29
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
30
+ gr.Markdown("# Chat with GPT-4.5")
31
+ gr.Markdown("Ask anything to gpt-4.5-preview-2025-02-27 model")
32
+
33
+ chatbot = gr.Chatbot()
34
+ with gr.Row():
35
+ msg = gr.Textbox(placeholder="Type your message here...", scale=4)
36
+ send = gr.Button("Send", scale=1)
37
+ clear = gr.Button("Clear")
38
+
39
+ # Set up interactions
40
+ send.click(respond, [msg, chatbot], [msg, chatbot])
41
+ msg.submit(respond, [msg, chatbot], [msg, chatbot]) # Keeps Enter key functionality
42
+ clear.click(lambda: None, None, chatbot, queue=False)
43
+
44
+ # Add example prompts
45
+ gr.Examples(
46
+ examples=["Tell me about quantum computing",
47
+ "Write a short poem about AI",
48
+ "How can I improve my Python skills?"],
49
+ inputs=msg
50
+ )
51
+
52
+ # Launch the app
53
+ if __name__ == "__main__":
54
+ demo.launch()