Spaces:
Running
Running
Commit
·
501ef44
1
Parent(s):
cc698c5
Remove repetition
Browse files
app.py
CHANGED
|
@@ -151,24 +151,22 @@ def Page():
|
|
| 151 |
with solara.Column(style={"width": "70%", "padding": "50px"}):
|
| 152 |
solara.Markdown(f"#{title}")
|
| 153 |
solara.Markdown("Enter some text and the language model will try to describe it as a knowledge graph. Done with :heart: by [alonsosilva](https://twitter.com/alonsosilva)")
|
| 154 |
-
extraction_stream = client.chat.completions.create_partial(
|
| 155 |
-
model="gpt-3.5-turbo",
|
| 156 |
-
response_model=KnowledgeGraph,
|
| 157 |
-
messages=[
|
| 158 |
-
{
|
| 159 |
-
"role": "user",
|
| 160 |
-
"content": f"Help me understand the following by describing it as small knowledge graph: {text_block}",
|
| 161 |
-
},
|
| 162 |
-
],
|
| 163 |
-
temperature=0,
|
| 164 |
-
stream=True,
|
| 165 |
-
)
|
| 166 |
-
|
| 167 |
user_message_count = len([m for m in messages.value if m["role"] == "user"])
|
| 168 |
def send():
|
| 169 |
-
messages.value = [{"role": "user", "content": ""}]
|
| 170 |
-
#messages.value = [*messages.value, {"role": "user", "content": ""}]
|
| 171 |
def response(message):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
for extraction in extraction_stream:
|
| 173 |
obj = extraction.model_dump()
|
| 174 |
if f"{obj}" != aux.value:
|
|
@@ -176,9 +174,10 @@ def Page():
|
|
| 176 |
aux.value = f"{obj}"
|
| 177 |
def result():
|
| 178 |
if messages.value != []:
|
| 179 |
-
|
|
|
|
| 180 |
result = solara.lab.use_task(result, dependencies=[user_message_count])
|
| 181 |
-
InputTextarea("Enter text:", value=text_block, continuous_update=
|
| 182 |
solara.Button(label="Generate Knowledge Graph", on_click=send)
|
| 183 |
ChatInterface()
|
| 184 |
Page()
|
|
|
|
| 151 |
with solara.Column(style={"width": "70%", "padding": "50px"}):
|
| 152 |
solara.Markdown(f"#{title}")
|
| 153 |
solara.Markdown("Enter some text and the language model will try to describe it as a knowledge graph. Done with :heart: by [alonsosilva](https://twitter.com/alonsosilva)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
user_message_count = len([m for m in messages.value if m["role"] == "user"])
|
| 155 |
def send():
|
| 156 |
+
messages.value = [*messages.value, {"role": "user", "content": " "}]
|
|
|
|
| 157 |
def response(message):
|
| 158 |
+
extraction_stream = client.chat.completions.create_partial(
|
| 159 |
+
model="gpt-3.5-turbo",
|
| 160 |
+
response_model=KnowledgeGraph,
|
| 161 |
+
messages=[
|
| 162 |
+
{
|
| 163 |
+
"role": "user",
|
| 164 |
+
"content": f"Help me understand the following by describing it as small knowledge graph: {text_block.value}",
|
| 165 |
+
},
|
| 166 |
+
],
|
| 167 |
+
temperature=0,
|
| 168 |
+
stream=True,
|
| 169 |
+
)
|
| 170 |
for extraction in extraction_stream:
|
| 171 |
obj = extraction.model_dump()
|
| 172 |
if f"{obj}" != aux.value:
|
|
|
|
| 174 |
aux.value = f"{obj}"
|
| 175 |
def result():
|
| 176 |
if messages.value != []:
|
| 177 |
+
if messages.value[-1]["role"] == "user":
|
| 178 |
+
response(messages.value[-1]["content"])
|
| 179 |
result = solara.lab.use_task(result, dependencies=[user_message_count])
|
| 180 |
+
InputTextarea("Enter text:", value=text_block, continuous_update=False)
|
| 181 |
solara.Button(label="Generate Knowledge Graph", on_click=send)
|
| 182 |
ChatInterface()
|
| 183 |
Page()
|