File size: 2,276 Bytes
4ecead1
e148f2b
 
82bc1c9
 
3fab6b8
 
82bc1c9
 
 
 
e9b97c6
82bc1c9
e148f2b
 
 
 
 
 
 
 
 
 
 
82bc1c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4ecead1
82bc1c9
 
3fab6b8
82bc1c9
 
3fab6b8
82bc1c9
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
57
import gradio as gr
from openai import OpenAIError

from selfinstruct.instance import instance_main
import openai
from langchain.llms.openai import OpenAI
import os
import json

def OpenaiChat(key, input, temperature):
    print(input)
    openai.api_key = key
    MODEL = "gpt-3.5-turbo"
    try:
        response = openai.ChatCompletion.create(
            model=MODEL,
            messages=[
                {"role": "user", "content": input}
            ],
            temperature=temperature
        )
        return json.dumps(response["choices"], ensure_ascii=False)
    except OpenAIError:
        return "Wrong Key!"

with gr.Blocks() as demo:
    gr.Markdown("# Self-instruct Prompt")
    with gr.Row():
        key = gr.Textbox(label="Input OpenAI key", type="password")
    with gr.Tab("Generate instance"):
        with gr.Row():
            with gr.Column():
                gr.Dropdown(["davinci"], value=["davinci"], multiselect=False, label="Model")
                text_input = gr.TextArea(lines=3, label="Input instruction:", info="格式:一行一个instruction")
            with gr.Column():
                text_output = gr.JSON(lines=10, label="Output instance:")
        text_button = gr.Button("Generate")
        gr.Markdown("## 3 Steps to generate")
        with gr.Row():
            text_step1 = gr.TextArea(lines=3, label="Step1 identify if classifacrion task:", )
            text_step2 = gr.TextArea(lines=3, label="Step2 generate instance:", )
            text_step3 = gr.TextArea(lines=3, label="Step3 Prepare for finetune:", )

    with gr.Tab("Simple ChatGPT"):
        gr.Dropdown(["GPT3.5"], value=["GPT3.5"], multiselect=False, label="Model")
        temperature = gr.Slider(0, 1.0, value=0.5, label="Temperature", info="Choose betwen 0 and 1")
        ChatGPT_input = gr.TextArea(lines=3, label="Input:")
        ChatGPT_output = gr.TextArea(lines=3, label="Output:")
        ChatGPT_button = gr.Button("Run")

    # with gr.Accordion("Open for More!"):
    #     gr.Markdown("Look at me...")

    text_button.click(instance_main, inputs=[text_input, key], outputs=[text_output, text_step1, text_step2, text_step3])
    ChatGPT_button.click(OpenaiChat, inputs=[key, ChatGPT_input, temperature], outputs=ChatGPT_output)

demo.launch()