|
import openai |
|
import os |
|
import gradio as gr |
|
openai.api_key=os.getenv('openai_appkey') |
|
|
|
def get_chatgpt(input_text): |
|
chat_completion = openai.ChatCompletion.create( |
|
model="gpt-3.5-turbo", |
|
messages=[ |
|
|
|
{"role": "system", "content": "You are a helpful assistant."}, |
|
|
|
{"role": "user", "content": input_text}, |
|
|
|
|
|
], |
|
) |
|
|
|
|
|
return chat_completion.choices[0].message.content |
|
with gr.Blocks( |
|
css=""" |
|
.message.svelte-w6rprc.svelte-w6rprc.svelte-w6rprc {font-size: 20px; margin-top: 20px} |
|
#component-21 > div.wrap.svelte-w6rprc {height: 600px;} |
|
""" |
|
) as iface: |
|
state = gr.State([]) |
|
|
|
|
|
|
|
|
|
|
|
with gr.Row(): |
|
with gr.Column(scale=1): |
|
with gr.Row(): |
|
with gr.Column(scale=1): |
|
chat_input = gr.Textbox(lines=1, label="Quesiton Input") |
|
with gr.Row(): |
|
clear_button = gr.Button(value="Clear", interactive=True) |
|
submit_button = gr.Button( |
|
value="提问", interactive=True, variant="primary" |
|
) |
|
|
|
with gr.Column(): |
|
caption_output_v1 = gr.Textbox(lines=0, label="答案") |
|
|
|
|
|
|
|
|
|
submit_button.click( |
|
get_chatgpt, |
|
[ |
|
chat_input, |
|
], |
|
[caption_output_v1], |
|
) |
|
|
|
examples=[["毛主席是什么时候出生的?"]] |
|
examples = gr.Examples( |
|
examples=examples, |
|
inputs=[image_input, chat_input], |
|
) |
|
|
|
iface.queue(concurrency_count=1, api_open=False, max_size=10) |
|
iface.launch(enable_queue=True) |