Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,28 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
|
|
4 |
|
|
|
5 |
|
6 |
-
with gr.Blocks() as
|
7 |
gr.Markdown(
|
8 |
"""
|
9 |
-
# OntoChat
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
of
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
18 |
)
|
19 |
|
20 |
with gr.Group():
|
@@ -26,64 +34,53 @@ with gr.Blocks() as user_story_interface:
|
|
26 |
api_key_btn = gr.Button(value="Set API Key")
|
27 |
api_key_btn.click(fn=set_openai_api_key, inputs=api_key, outputs=api_key)
|
28 |
|
|
|
29 |
with gr.Row():
|
30 |
-
with gr.Column():
|
31 |
-
user_story_chatbot = gr.Chatbot(
|
32 |
-
[
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
36 |
user_story_input = gr.Textbox(
|
37 |
-
label="
|
38 |
-
placeholder="Please type your message here and press Enter to interact with the chatbot
|
|
|
|
|
39 |
)
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
label="User story",
|
54 |
-
interactive=True
|
55 |
-
)
|
56 |
user_story_input.submit(
|
57 |
fn=user_story_generator,
|
58 |
-
inputs=[
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
]
|
64 |
)
|
65 |
-
|
|
|
|
|
|
|
|
|
66 |
|
67 |
with gr.Blocks() as cq_interface:
|
68 |
-
gr.Markdown(
|
69 |
-
"""
|
70 |
-
# OntoChat
|
71 |
-
This is the second step of OntoChat. This functionality provides support for the extraction of competency
|
72 |
-
questions from a user story. Please, provide a user story to start extracting competency questions with the
|
73 |
-
chatbot, or simply load the example story below.
|
74 |
-
"""
|
75 |
-
)
|
76 |
-
|
77 |
-
with gr.Group():
|
78 |
-
api_key = gr.Textbox(
|
79 |
-
label="OpenAI API Key",
|
80 |
-
placeholder="If you have set the key in other tabs, you don't have to set it again.",
|
81 |
-
info="Please input your OpenAI API Key if you don't have it set up on your own machine. Please note that "
|
82 |
-
"the key will only be used for this demo and will not be uploaded or used anywhere else."
|
83 |
-
)
|
84 |
-
api_key_btn = gr.Button(value="Set API Key")
|
85 |
-
api_key_btn.click(fn=set_openai_api_key, inputs=api_key, outputs=api_key)
|
86 |
-
|
87 |
with gr.Row():
|
88 |
with gr.Column():
|
89 |
cq_chatbot = gr.Chatbot([
|
@@ -93,7 +90,7 @@ with gr.Blocks() as cq_interface:
|
|
93 |
])
|
94 |
cq_input = gr.Textbox(
|
95 |
label="Chatbot input",
|
96 |
-
placeholder="Please type your message here and press Enter to interact with the chatbot
|
97 |
)
|
98 |
gr.Markdown(
|
99 |
"""
|
@@ -102,7 +99,6 @@ with gr.Blocks() as cq_interface:
|
|
102 |
[Linka](https://github.com/polifonia-project/stories/tree/main/Linka_Computer_Scientist) in Polifonia.
|
103 |
"""
|
104 |
)
|
105 |
-
# TODO: could add more examples using Dropdown or CheckboxGroup
|
106 |
example_btn = gr.Button(value="Use example user story")
|
107 |
example_btn.click(
|
108 |
fn=load_example_user_story,
|
@@ -123,7 +119,6 @@ with gr.Blocks() as cq_interface:
|
|
123 |
]
|
124 |
)
|
125 |
|
126 |
-
|
127 |
clustering_interface = gr.Interface(
|
128 |
fn=clustering_generator,
|
129 |
inputs=[
|
@@ -158,11 +153,10 @@ clustering_interface = gr.Interface(
|
|
158 |
allow_flagging="never"
|
159 |
)
|
160 |
|
161 |
-
|
162 |
with gr.Blocks() as testing_interface:
|
163 |
gr.Markdown(
|
164 |
"""
|
165 |
-
# OntoChat
|
166 |
This is the final part of OntoChat which performs ontology testing based on the input ontology file and CQs.
|
167 |
"""
|
168 |
)
|
@@ -199,12 +193,10 @@ with gr.Blocks() as testing_interface:
|
|
199 |
]
|
200 |
)
|
201 |
|
202 |
-
|
203 |
demo = gr.TabbedInterface(
|
204 |
-
[user_story_interface, cq_interface, clustering_interface, testing_interface],
|
205 |
-
["User Story Generation", "Competency Question Extraction", "Competency Question Analysis", "Ontology Testing"]
|
206 |
)
|
207 |
|
208 |
-
|
209 |
if __name__ == "__main__":
|
210 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from ontochat.functions import set_openai_api_key, user_story_generator, cq_generator, load_example_user_story, clustering_generator, ontology_testing, get_preidentified_prompts, load_example, update_examples
|
3 |
|
4 |
+
# Global variables to hold pre-identified prompts
|
5 |
+
preidentified_prompts = get_preidentified_prompts()
|
6 |
|
7 |
+
user_story_template = """**Persona:**\n\n- Name: -\n- Age: -\n- Occupation: -\n- Skills: -\n- Interests: -\n\n**Goal:**\n\n- Description: -\n- Keywords: -\n\n**Scenario:**\n\n- Before: -\n- During: -\n- After: -\n\n**Example Data:**\n\n- Category: -\n- Data: -\n\n**Resources:**\n\n- Resource Name: -\n- Link: -"""
|
8 |
|
9 |
+
with gr.Blocks() as set_api_key:
|
10 |
gr.Markdown(
|
11 |
"""
|
12 |
+
# Welcome to OntoChat! 👋
|
13 |
+
|
14 |
+
**Hello! I'm OntoChat, your conversational ontology engineering assistant.** 🎉
|
15 |
+
|
16 |
+
I'm here to help you streamline the complex process of building and refining ontologies. Whether you're collecting requirements, generating user stories, extracting competency questions, or testing early versions of your ontology, I've got you covered! You can use me to:
|
17 |
+
|
18 |
+
- **Collaboratively create user stories** tailored to your domain.
|
19 |
+
- **Automatically extract and refine competency questions** from your stories.
|
20 |
+
- **Cluster and analyze competency questions** to identify patterns and gaps in your requirements.
|
21 |
+
- **Test and verify your ontology's design** without needing to write queries manually.
|
22 |
+
|
23 |
+
Let's work together to simplify your ontology engineering process!
|
24 |
+
Visit [OntoChat on GitHub](https://github.com/King-s-Knowledge-Graph-Lab/OntoChat) for more information.
|
25 |
+
"""
|
26 |
)
|
27 |
|
28 |
with gr.Group():
|
|
|
34 |
api_key_btn = gr.Button(value="Set API Key")
|
35 |
api_key_btn.click(fn=set_openai_api_key, inputs=api_key, outputs=api_key)
|
36 |
|
37 |
+
with gr.Blocks() as user_story_interface:
|
38 |
with gr.Row():
|
39 |
+
with gr.Column(scale=1):
|
40 |
+
user_story_chatbot = gr.Chatbot(
|
41 |
+
[
|
42 |
+
[None, "Hi there! I'm OntoChat, your go-to assistant for building ontologies. 😊\n"
|
43 |
+
"I'll be helping you create a user story by asking a few questions and answering anything you're curious about along the way.\n"
|
44 |
+
"Let's get started! Can you share a bit about what this ontology is for?"
|
45 |
+
],
|
46 |
+
],
|
47 |
+
height="572px"
|
48 |
+
)
|
49 |
user_story_input = gr.Textbox(
|
50 |
+
label="Message OntoChat",
|
51 |
+
placeholder="Please type your message here and press Shift + Enter to interact with the chatbot:",
|
52 |
+
max_lines=2,
|
53 |
+
lines = 2
|
54 |
)
|
55 |
+
elicitation_questions_dataset = gr.Dataset(
|
56 |
+
components=[user_story_input],
|
57 |
+
label="Suggestion",
|
58 |
+
type="index",
|
59 |
+
samples=[
|
60 |
+
["Cultural Heritage Preservation"],
|
61 |
+
["Accessibility and Inclusion"],
|
62 |
+
["Multisensory Interactions"],
|
63 |
+
["Digital Rights and Preservation"]
|
64 |
+
],
|
65 |
+
samples_per_page = 10
|
66 |
+
)
|
67 |
+
|
|
|
|
|
|
|
68 |
user_story_input.submit(
|
69 |
fn=user_story_generator,
|
70 |
+
inputs=[user_story_input, user_story_chatbot],
|
71 |
+
outputs=[user_story_chatbot, user_story_input, elicitation_questions_dataset]
|
72 |
+
).then(
|
73 |
+
fn=update_examples,
|
74 |
+
inputs=None,
|
75 |
+
outputs=[elicitation_questions_dataset]
|
76 |
)
|
77 |
+
elicitation_questions_dataset.click(
|
78 |
+
fn=load_example,
|
79 |
+
inputs=[elicitation_questions_dataset],
|
80 |
+
outputs=[user_story_input]
|
81 |
+
)
|
82 |
|
83 |
with gr.Blocks() as cq_interface:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
with gr.Row():
|
85 |
with gr.Column():
|
86 |
cq_chatbot = gr.Chatbot([
|
|
|
90 |
])
|
91 |
cq_input = gr.Textbox(
|
92 |
label="Chatbot input",
|
93 |
+
placeholder="Please type your message here and press Enter to interact with the chatbot:"
|
94 |
)
|
95 |
gr.Markdown(
|
96 |
"""
|
|
|
99 |
[Linka](https://github.com/polifonia-project/stories/tree/main/Linka_Computer_Scientist) in Polifonia.
|
100 |
"""
|
101 |
)
|
|
|
102 |
example_btn = gr.Button(value="Use example user story")
|
103 |
example_btn.click(
|
104 |
fn=load_example_user_story,
|
|
|
119 |
]
|
120 |
)
|
121 |
|
|
|
122 |
clustering_interface = gr.Interface(
|
123 |
fn=clustering_generator,
|
124 |
inputs=[
|
|
|
153 |
allow_flagging="never"
|
154 |
)
|
155 |
|
|
|
156 |
with gr.Blocks() as testing_interface:
|
157 |
gr.Markdown(
|
158 |
"""
|
159 |
+
# OntoChat
|
160 |
This is the final part of OntoChat which performs ontology testing based on the input ontology file and CQs.
|
161 |
"""
|
162 |
)
|
|
|
193 |
]
|
194 |
)
|
195 |
|
|
|
196 |
demo = gr.TabbedInterface(
|
197 |
+
[set_api_key, user_story_interface, cq_interface, clustering_interface, testing_interface],
|
198 |
+
["Set API Key", "User Story Generation", "Competency Question Extraction", "Competency Question Analysis", "Ontology Testing"]
|
199 |
)
|
200 |
|
|
|
201 |
if __name__ == "__main__":
|
202 |
+
demo.launch(share=True)
|