Javierquin commited on
Commit
1e93383
·
verified ·
1 Parent(s): 04a0bf0

create main.ppy

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from openai import AzureOpenAI
4
+
5
+ client = AzureOpenAI(
6
+ api_key=os.getenv("AZURE_KEY"),
7
+ api_version=os.getenv("AZURE_VERSION"),
8
+ azure_endpoint=os.getenv("AZURE_URL")
9
+ )
10
+
11
+ def chat_with_gpt4o(message, chat_history, company_data, objective, other):
12
+ chat_history = chat_history or []
13
+
14
+ # If this is the first message, add the initial greeting
15
+ if not chat_history:
16
+ initial_greeting = "Hola soy el asistente de Horizon, en que te puedo ayudar?"
17
+ chat_history.append(("", initial_greeting))
18
+ return "", chat_history
19
+
20
+ # Create a detailed system prompt with the additional information
21
+ system_prompt = f"""You are a helpful assistant. Here is some context about the conversation:
22
+ Company Data: {company_data}
23
+ Objective: {objective}
24
+ Other Information: {other}"""
25
+
26
+ # Initialize messages with the enhanced system prompt
27
+ messages = [{"role": "system", "content": system_prompt}]
28
+ # Append previous conversation
29
+ for user, assistant in chat_history:
30
+ messages.append({"role": "user", "content": user})
31
+ messages.append({"role": "assistant", "content": assistant})
32
+ # Add the new user message
33
+ messages.append({"role": "user", "content": message})
34
+
35
+ # Call the Azure OpenAI API
36
+ response = client.chat.completions.create(
37
+ model="gpt-4o", # Usa el nombre del deployment
38
+ messages=messages
39
+ )
40
+ assistant_message = response.choices[0].message.content
41
+
42
+ # Update chat history
43
+ chat_history.append((message, assistant_message))
44
+ # Clear the input box and return updated history
45
+ return "", chat_history
46
+
47
+ with gr.Blocks() as demo:
48
+ with gr.Row():
49
+ company_data = gr.Textbox(label="Company Data", placeholder="Enter company information...")
50
+ objective = gr.Textbox(label="Objective", placeholder="Enter the objective...")
51
+ other = gr.Textbox(label="Other", placeholder="Enter any other relevant information...")
52
+
53
+ with gr.Row():
54
+ with gr.Column(scale=2): # Chat section (2/3)
55
+ chatbot = gr.Chatbot(label="GPT-4o Chat", value=[("", "Hola soy el asistente de Horizon, en que te puedo ayudar?")])
56
+ msg = gr.Textbox(placeholder="Type your message here...", show_label=False)
57
+ msg.submit(chat_with_gpt4o, [msg, chatbot, company_data, objective, other], [msg, chatbot])
58
+
59
+ with gr.Column(scale=1): # Reasoning section (1/3)
60
+ reasoning = gr.Textbox(label="Reasoning", lines=20, interactive=False)
61
+
62
+ demo.launch()