File size: 1,267 Bytes
a20ccd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from utils.api.GPT import generate_answers_openai, Session
import numpy as np
import os
import time

def generate_interface(prompt, description=None):
    session = Session(prompt)
    def _fun(customer_input):
        print("(Q:) ", customer_input)
        response = generate_answers_openai(customer_input, session)
        print("(A:) ", response)
        return session.to_conversation_pair()
    
    interface = gr.Interface(description=description, fn=_fun, 
                             inputs=[gr.Textbox(lines=1, label="input")], 
                             outputs=[gr.Chatbot(label="conversation")])
    return interface

prompts = [
    {"name": "Summary", "prompt": "Based on the language of human in the conversation, you will generate a report to assess the English level, summarize the conversation, and provide suggestions to improve the language. Conservation:{}", "description": "generate report."},
    
]

interfaces = []
names = []
for function in prompts:
    interface = generate_interface(function['prompt'], function['description'])
    interfaces.append(interface)
    names.append(function['name'])
    
demo = gr.TabbedInterface(interfaces, names,title="Role Play Bot")

if __name__ == '__main__':
    demo.launch()