File size: 1,783 Bytes
55b5946
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from utils import *
import openai

def greet(task, human_input, cooperate_style):
    merged_answer = "xxx"
    return f"Given task :{task},\nthe {cooperate_style} answer based of ai and human input \"{human_input}\" is:\n {merged_answer}. "

def get_answer(task, human_input, cooperate_style):
    if cooperate_style=="sequential":
            merged_text = merge_texts_sequential(task, human_input)
            print(f"AI merged text: {merged_text}")
    else:
        generated_text = generate_text_with_gpt(task)
        print(f"AI provided text: {generated_text}")    
        merged_text = merge_texts_parallel(task, human_input, generated_text)
    return merged_text

def main():
    with gr.Blocks() as demo:
        task = gr.Textbox(label="Please Give a task description.")
        human_input = gr.Textbox(label="Please provide a human answer.", value = "Write a poem about the moon.")
        cooperate_style = gr.Radio(['sequential', 'parallel'], label="What type of cooperation would you like?")
        greet_btn = gr.Button("Think!")
        output = gr.Textbox(label="Answer with cooperation")
        
        greet_btn.click(fn=get_answer, 
                        inputs=[task, human_input, cooperate_style], 
                        outputs=output, 
                        api_name="answer")
        
        evaluate_btn = gr.Button("Evaluate")
        evaluation_results = gr.Textbox(label="Evaluation results.")
        evaluate_btn.click(fn= evaluation,
                           inputs=[task, output],
                           outputs= evaluation_results,
                           api_name = "evaluate")
        demo.launch(share=True)
    
if __name__ == "__main__":
    main()