Spaces:
Sleeping
Sleeping
Commit
·
5fb50e6
1
Parent(s):
12c7670
Add JSON parsing and format output in HTML
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
from os import environ as env
|
| 2 |
from os import system as run
|
| 3 |
from subprocess import check_output
|
|
@@ -65,23 +66,39 @@ Help make the internet a kinder place, one comment at a time.
|
|
| 65 |
Your contribution could make a big difference!
|
| 66 |
"""
|
| 67 |
|
| 68 |
-
|
| 69 |
-
# Now chill can import llama-cpp-python without an error:
|
| 70 |
from chill import improvement_loop
|
| 71 |
|
| 72 |
|
| 73 |
def chill_out(text):
|
| 74 |
print("Got this input:", text)
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
demo = gr.Interface(
|
| 79 |
fn=chill_out,
|
| 80 |
-
inputs="text",
|
| 81 |
-
outputs="
|
| 82 |
examples=examples,
|
| 83 |
cache_examples=True,
|
| 84 |
-
description=description
|
|
|
|
|
|
|
| 85 |
)
|
| 86 |
|
| 87 |
demo.launch(max_threads=1, share=True)
|
|
|
|
| 1 |
+
import json
|
| 2 |
from os import environ as env
|
| 3 |
from os import system as run
|
| 4 |
from subprocess import check_output
|
|
|
|
| 66 |
Your contribution could make a big difference!
|
| 67 |
"""
|
| 68 |
|
|
|
|
|
|
|
| 69 |
from chill import improvement_loop
|
| 70 |
|
| 71 |
|
| 72 |
def chill_out(text):
|
| 73 |
print("Got this input:", text)
|
| 74 |
+
result: str = improvement_loop(text)
|
| 75 |
+
print("Got this result:", result)
|
| 76 |
+
result: dict = json.loads(result)
|
| 77 |
+
|
| 78 |
+
formatted_output = f"""
|
| 79 |
+
<div>
|
| 80 |
+
<h4>Edited text:</h4>
|
| 81 |
+
<p>{result['edit']}</p>
|
| 82 |
+
<h4>Details:</h4>
|
| 83 |
+
<ul>
|
| 84 |
+
<li>Critique: {result['critique']}</li>
|
| 85 |
+
<li>Faithfulness Score: {result['faithfulness_score']}</li>
|
| 86 |
+
<li>Spicy Score: {result['spicy_score']}</li>
|
| 87 |
+
<li>Overall Score: {result['overall_score']}</li>
|
| 88 |
+
</ul>
|
| 89 |
+
</div>
|
| 90 |
+
"""
|
| 91 |
+
return formatted_output
|
| 92 |
|
| 93 |
demo = gr.Interface(
|
| 94 |
fn=chill_out,
|
| 95 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter some spicy text here..."),
|
| 96 |
+
outputs="html",
|
| 97 |
examples=examples,
|
| 98 |
cache_examples=True,
|
| 99 |
+
description=description,
|
| 100 |
+
title="ChillTranslator",
|
| 101 |
+
allow_flagging=False,
|
| 102 |
)
|
| 103 |
|
| 104 |
demo.launch(max_threads=1, share=True)
|