IIFAN commited on
Commit
0acc588
1 Parent(s): 29aa6df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -51
app.py CHANGED
@@ -1,56 +1,22 @@
1
  import gradio as gr
2
- import os
3
- import json
4
- from bot import run_chatbot
5
-
6
- #Resetting to blank
7
- def reset_textbox():
8
- return gr.update(value='')
9
 
10
- #to set a component as visible=False
11
- def set_visible_false():
12
- return gr.update(visible=False)
13
 
14
- #to set a component as visible=True
15
- def set_visible_true():
16
- return gr.update(visible=True)
 
 
 
 
 
17
 
18
- title = """<h1 align="center">NPC 测试</h1>"""
 
 
19
 
20
- character = "paul"
21
-
22
- #Modifying existing Gradio Theme
23
- theme = gr.themes.Soft(primary_hue="zinc", secondary_hue="green", neutral_hue="green",
24
- text_size=gr.themes.sizes.text_lg)
25
-
26
- with gr.Blocks(css = """#col_container { margin-left: auto; margin-right: auto;} #chatbot {height: 520px; overflow: auto;}""", theme=theme) as demo:
27
- gr.HTML(title)
28
- with gr.Column(elem_id = "col_container"):
29
- #Users need to provide their own GPT4 API key, it is no longer provided by Huggingface
30
- with gr.Row():
31
- openai_gpt4_key = gr.Textbox(label="OpenAI GPT4 Key", value="", type="password", placeholder="sk..", info = "You have to provide your own GPT4 keys for this app to function properly",)
32
-
33
- chatbot = gr.Textbox(label='GPT4', elem_id="chatbot")
34
- inputs = gr.Textbox(placeholder= "Hi there!", label= "你对NPC说的话")
35
- character = gr.Textbox(placeholder= "paul", label= "NPC名字")
36
- state = gr.State([])
37
- with gr.Row():
38
- with gr.Column(scale=7):
39
- b1 = gr.Button()
40
- with gr.Column(scale=3):
41
- server_status_code = gr.Textbox(label="Status code from OpenAI server", )
42
-
43
- #top_p, temperature
44
- # with gr.Accordion("Parameters", open=False):
45
- # top_p = gr.Slider( minimum=-0, maximum=1.0, value=1.0, step=0.05, interactive=True, label="Top-p (nucleus sampling)",)
46
- # temperature = gr.Slider( minimum=-0, maximum=5.0, value=1.0, step=0.1, interactive=True, label="Temperature",)
47
- # chat_counter = gr.Number(value=0, visible=False, precision=0)
48
-
49
- #Event handling
50
- inputs.submit(run_chatbot, [openai_gpt4_key, character, inputs],[chatbot])
51
- b1.click(run_chatbot, [openai_gpt4_key, character, inputs],[chatbot])
52
-
53
- b1.click(reset_textbox, [], [inputs])
54
- inputs.submit(reset_textbox, [], [inputs])
55
-
56
- demo.launch(debug=True)
 
1
  import gradio as gr
2
+ import openai
 
 
 
 
 
 
3
 
4
+ # Set up your OpenAI API key for GPT-3.5
5
+ openai.api_key = "YOUR_API_KEY_HERE"
 
6
 
7
+ # Function to interact with GPT-3.5
8
+ def interact_with_gpt(prompt):
9
+ response = openai.Completion.create(
10
+ engine="text-davinci-003",
11
+ prompt=prompt,
12
+ max_tokens=100
13
+ )
14
+ return response.choices[0].text.strip()
15
 
16
+ # Create Gradio interface
17
+ input_text = gr.inputs.Textbox(label="Input Text")
18
+ output_text = gr.outputs.Textbox(label="Output Text")
19
 
20
+ title = "GPT-3.5 Chatbot"
21
+ description = "Enter your text, and GPT-3.5 will respond."
22
+ gr.Interface(interact_with_gpt, input_text, output_text, title=title, description=description).launch()