-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathuser_interface.py
85 lines (65 loc) · 2.76 KB
/
user_interface.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import gradio as gr
from commons.ThinkerInterface import Thinker
class Wrapper:
def __init__(self) -> None:
pass
async def thinker_wrapper_function(self, situation: str, thoughts: str) -> list:
"""
This function is an asynchronous function used to encapsulate the use of the Thinker class.
Parameters:
situation (str): Represents the current situation.
thoughts (str): Represents the current thoughts.
Returns:
list: A list of suggestions generated by the Thinker class.
"""
self.thinker: Thinker = Thinker(
situation=situation,
thoughts=thoughts
)
await self.thinker.query_process()
return self.thinker.the_suggestions
async def elaboration_wrapper_function(self, selected_suggestion: int) -> str:
"""
The function `elaboration_wrapper_function` takes in a selected suggestion and returns the
elaboration generated by the `think_process` method of the `thinker` object.
:param selected_suggestion: The `selected_suggestion` parameter is an integer that represents
the index of the suggestion that the user has selected. It is used as an input to the
`think_process` method of the `thinker` object
:type selected_suggestion: int
:return: a string, which is the elaboration generated by the `think_process` method of the
`thinker` object.
"""
elaboration: str = await self.thinker.think_process(selected_suggestion=selected_suggestion)
return elaboration
if __name__ == '__main__':
import logging
import os
logging.basicConfig(level=logging.INFO)
os.environ['TOKENIZERS_PARALLELISM'] = "false"
wrapper: Wrapper = Wrapper()
interface: gr.Interface = gr.Interface(
fn=wrapper.thinker_wrapper_function,
inputs=[
gr.components.Textbox(
"Situation",
placeholder="Enter your situation here",
default="I am feeling tired"
),
gr.components.Textbox(
"Thoughts",
placeholder="Enter your thoughts here",
default="I am feeling tired"
)
],
outputs=[
gr.components.Textbox(label="Suggestions"),
gr.components.Textbox(label="Elaboration")
],
title="Thinker",
description="A tool to help you think and make decisions",
article="This tool is a wrapper for the Thinker class, which is a class that helps you think and make decisions.",
examples=[
["I am feeling tired", "I am feeling tired"],
]
)
interface.launch()