Spaces:
Sleeping
Sleeping
Naisong Zhou
commited on
Commit
·
d09ee55
1
Parent(s):
52865f0
revise to demanded app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,38 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
def greet(
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 7 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from utils import *
|
| 3 |
+
import openai
|
| 4 |
|
| 5 |
+
def greet(task, human_input, cooperate_style):
|
| 6 |
+
merged_answer = "xxx"
|
| 7 |
+
return f"Given task :{task},\nthe {cooperate_style} answer based of ai and human input \"{human_input}\" is:\n {merged_answer}. "
|
| 8 |
+
|
| 9 |
+
def get_answer(task, human_input, cooperate_style):
|
| 10 |
+
if cooperate_style=="sequential":
|
| 11 |
+
merged_text = merge_texts_sequential(task, human_input)
|
| 12 |
+
print(f"AI merged text: {merged_text}")
|
| 13 |
+
else:
|
| 14 |
+
generated_text = generate_text_with_gpt(task)
|
| 15 |
+
print(f"AI provided text: {generated_text}")
|
| 16 |
+
merged_text = merge_texts_parallel(task, human_input, generated_text)
|
| 17 |
+
return merged_text
|
| 18 |
+
|
| 19 |
+
with gr.Blocks() as demo:
|
| 20 |
+
task = gr.Textbox(label="Please Give a task description.")
|
| 21 |
+
human_input = gr.Textbox(label="Please provide a human answer.", value = "Write a poem about the moon.")
|
| 22 |
+
cooperate_style = gr.Radio(['sequential', 'parallel'], label="What type of cooperation would you like?")
|
| 23 |
+
greet_btn = gr.Button("Think!")
|
| 24 |
+
output = gr.Textbox(label="Answer with cooperation")
|
| 25 |
+
|
| 26 |
+
greet_btn.click(fn=get_answer,
|
| 27 |
+
inputs=[task, human_input, cooperate_style],
|
| 28 |
+
outputs=output,
|
| 29 |
+
api_name="answer")
|
| 30 |
+
|
| 31 |
+
evaluate_btn = gr.Button("Evaluate")
|
| 32 |
+
evaluation_results = gr.Textbox(label="Evaluation results.")
|
| 33 |
+
evaluate_btn.click(fn= evaluation,
|
| 34 |
+
inputs=[task, output],
|
| 35 |
+
outputs= evaluation_results,
|
| 36 |
+
api_name = "evaluate")
|
| 37 |
+
demo.launch(share=True)
|
| 38 |
|
|
|
|
|
|