zns0327's picture
Update app.py
11fc848 verified
Raw
History Blame
1.61 kB
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
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("Create!")
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)