TuanScientist commited on
Commit
265dbd1
·
1 Parent(s): 5fc4d5a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -22
app.py CHANGED
@@ -14,43 +14,30 @@ outputs = [
14
  gr.outputs.Textbox(label="Câu trả lời:")
15
  ]
16
 
17
- # Initialize conversation history
18
- conversation_history = []
19
-
20
  def chatbot(input):
21
- global conversation_history
22
  openai.api_key = "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"
23
 
24
- # Add user input to conversation history
25
- conversation_history.append(f"You: {input}")
26
-
27
- # Generate response using conversation history
28
  response = openai.Completion.create(
29
  engine="text-davinci-003",
30
- prompt='\n'.join(conversation_history),
31
  max_tokens=600
32
  )
33
 
34
- # Add AI response to conversation history
35
- ai_response = response.choices[0].text.strip()
36
- conversation_history.append(ai_response) # Remove the ": " prefix
37
-
38
- return ai_response
39
 
40
- # Create a Gradio interface
41
  interface = gr.Interface(
42
  fn=chatbot,
43
  inputs=inputs,
44
  outputs=outputs,
45
- title="AI Consultant",
46
- theme="compact",
47
- layout="vertical",
48
  allow_flagging="never",
49
- live=False,
50
- description=DESCRIPTION,
51
  css='style.css'
52
  )
53
-
54
  # Launch the interface
55
  interface.launch()
56
-
 
14
  gr.outputs.Textbox(label="Câu trả lời:")
15
  ]
16
 
 
 
 
17
  def chatbot(input):
 
18
  openai.api_key = "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"
19
 
 
 
 
 
20
  response = openai.Completion.create(
21
  engine="text-davinci-003",
22
+ prompt=input,
23
  max_tokens=600
24
  )
25
 
26
+ return response.choices[0].text.strip()
27
+
28
+ # Create a Gradio interface with title, logo, and caption
 
 
29
 
 
30
  interface = gr.Interface(
31
  fn=chatbot,
32
  inputs=inputs,
33
  outputs=outputs,
34
+ title="AI Consultant", # Add the title here
35
+ theme="compact", # You can adjust the theme as needed
36
+ layout="vertical", # You can adjust the layout as needed
37
  allow_flagging="never",
38
+ live=False, # Set live to False to display the title, logo, and caption immediately
39
+ description=DESCRIPTION, # Update the description here
40
  css='style.css'
41
  )
 
42
  # Launch the interface
43
  interface.launch()