File size: 1,267 Bytes
3eed6e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e973c3a
 
 
3eed6e5
e973c3a
11c687a
3eed6e5
e973c3a
 
 
 
3eed6e5
 
e973c3a
29b56a4
3eed6e5
 
e973c3a
 
29b56a4
e973c3a
 
3eed6e5
e973c3a
3eed6e5
 
 
 
e973c3a
 
 
3eed6e5
e973c3a
 
3eed6e5
 
e973c3a
3eed6e5
e973c3a
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
import gradio as gr
import openai

DESCRIPTION = """
Hãy để trợ lý của AI Consultant hỗ trợ bạn !
"""

# Define inputs and outputs
inputs = [
    gr.inputs.Textbox(label="Câu hỏi:"),
]

outputs = [
    gr.outputs.Textbox(label="Câu trả lời:")
]

# Initialize conversation history
conversation_history = []

def chatbot(input):
    global conversation_history
    openai.api_key = "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"
    
    # Add user input to conversation history
    conversation_history.append(f"You: {input}")
    
    # Generate response using conversation history
    response = openai.Completion.create(
        engine="text-davinci-003",
        prompt='\n'.join(conversation_history),
        max_tokens=600
    )
    
    # Add AI response to conversation history
    ai_response = response.choices[0].text.strip()
    conversation_history.append(f": {ai_response}")
    
    return ai_response

# Create a Gradio interface
interface = gr.Interface(
    fn=chatbot,
    inputs=inputs,
    outputs=outputs,
    title="AI Consultant",
    theme="compact",
    layout="vertical",
    allow_flagging="never",
    live=False,
    description=DESCRIPTION,
    css='style.css'
)

# Launch the interface
interface.launch()