Spaces:
Runtime error
Runtime error
Commit
·
929859d
1
Parent(s):
b959fcb
Update app.py
Browse files
app.py
CHANGED
@@ -2,54 +2,42 @@ import gradio as gr
|
|
2 |
import openai
|
3 |
|
4 |
DESCRIPTION = """
|
5 |
-
Hãy để trợ lý của AI Consultant hỗ trợ bạn!
|
6 |
"""
|
7 |
|
8 |
# Define inputs and outputs
|
9 |
inputs = [
|
10 |
-
gr.inputs.Textbox(label="
|
11 |
]
|
12 |
|
13 |
outputs = [
|
14 |
gr.outputs.Textbox(label="Câu trả lời:")
|
15 |
]
|
16 |
|
17 |
-
|
18 |
-
conversation_history = []
|
19 |
-
|
20 |
-
def chatbot(history):
|
21 |
-
global conversation_history
|
22 |
openai.api_key = "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"
|
23 |
|
24 |
-
# Use the provided history as conversation history
|
25 |
-
conversation_history = history.split('\n')
|
26 |
-
|
27 |
-
# Generate response using conversation history
|
28 |
response = openai.Completion.create(
|
29 |
engine="text-davinci-003",
|
30 |
-
prompt=
|
31 |
-
max_tokens=
|
32 |
)
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
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()
|
|
|
2 |
import openai
|
3 |
|
4 |
DESCRIPTION = """
|
5 |
+
Hãy để trợ lý của AI Consultant hỗ trợ bạn !
|
6 |
"""
|
7 |
|
8 |
# Define inputs and outputs
|
9 |
inputs = [
|
10 |
+
gr.inputs.Textbox(label="Câu hỏi:"),
|
11 |
]
|
12 |
|
13 |
outputs = [
|
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=100
|
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()
|