Spaces:
Runtime error
Runtime error
import gradio as gr | |
from llama_cpp import Llama | |
llm = Llama(model_path="ggml-model-q4_0.bin", n_threads=8, n_ctx=2048, n_batch=128) | |
def generate_text(input_text): | |
output = llm(f"{input_text}", max_tokens=200, stop=[], echo=False) | |
return output['choices'][0]['text'] | |
def main(): | |
app = gr.Blocks() | |
try: | |
with app: | |
title = "Dcard Emotion Post 0.1 Demo" | |
desc = """ small dcard post generate. <br /> | |
Enter the beginning of story and click the button <br /> | |
It's just a simplified demo, you can use more advanced features optimize quality <br />""" | |
tutorial_link = "https://docs.cworld.ai" | |
gr.HTML( | |
f""" | |
<div style="text-align: center; margin: 0 auto;"> | |
<a href="https://cworld.ai"> | |
<svg style="margin: 0 auto;" width="155" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 407 100"> | |
<g id="SvgjsG2746" | |
transform="matrix(0.8454106280193237,0,0,0.8454106280193237,-4.2270531400966185,-4.2270531400966185)" | |
fill="#111"> | |
<g xmlns="http://www.w3.org/2000/svg"> | |
<g> | |
<g> | |
<path d="M50,11c21.5,0,39,17.5,39,39S71.5,89,50,89S11,71.5,11,50S28.5,11,50,11 M50,5C25.1,5,5,25.1,5,50s20.1,45,45,45 s45-20.1,45-45S74.9,5,50,5L50,5z"></path> | |
</g> | |
</g> | |
<path d="M55,75H45v-5c0-2.8,2.2-5,5-5h0c2.8,0,5,2.2,5,5V75z"></path> | |
<rect x="25" y="35" width="10" height="20"></rect> | |
<rect x="65" y="35" width="10" height="20"></rect> | |
</g> | |
</g> | |
<g id="SvgjsG2747" | |
transform="matrix(3.3650250410766605,0,0,3.3650250410766605,93.98098208712985,-3.546415304677616)" | |
fill="#111"> | |
<path | |
d="M8.1 17.42 l1.42 1.28 c-0.94 1.04 -2.28 1.5 -3.78 1.5 c-2.84 0 -5.14 -2.18 -5.14 -5.12 s2.3 -5.14 5.14 -5.14 c1.5 0 2.84 0.46 3.78 1.5 l-1.42 1.28 c-0.58 -0.78 -1.42 -1.08 -2.36 -1.08 c-1.7 0 -3.08 1.42 -3.08 3.44 c0 2 1.38 3.44 3.08 3.44 c0.94 0 1.78 -0.3 2.36 -1.1 z M23.42 10.12 l2.06 0 l-3.76 9.88 l-1.26 0 l-2.46 -6.4 l-2.44 6.4 l-1.26 0 l-3.78 -9.88 l2.08 0 l2.34 6.9 l2.06 -6.08 l0.26 -0.82 l1.48 0 l0.28 0.82 l2.06 6.08 z M31.62 11.64 c-1.7 0 -3.08 1.42 -3.08 3.44 c0 2 1.38 3.44 3.08 3.44 s3.08 -1.44 3.08 -3.44 c0 -2.02 -1.38 -3.44 -3.08 -3.44 z M31.62 9.94 c2.84 0 5.14 2.2 5.14 5.14 s-2.3 5.12 -5.14 5.12 s-5.14 -2.18 -5.14 -5.12 s2.3 -5.14 5.14 -5.14 z M44.9 10.24 l-0.44 1.62 c-0.14 -0.08 -0.58 -0.22 -0.94 -0.22 c-1.7 0 -2.5 1.62 -2.5 3.62 l0 4.74 l-2.06 0 l0 -9.88 l2.06 0 l0 1.4 c0.24 -0.92 1.3 -1.58 2.48 -1.58 c0.54 0 1.12 0.14 1.4 0.3 z M48.379999999999995 4.619999999999999 l0 15.38 l-2.08 0 l0 -15.38 l2.08 0 z M50.98 15.08 c0 -2.94 2.1 -5.14 4.94 -5.14 c0.98 0 2.18 0.42 2.84 0.96 l0 -5.9 l2.08 0 l0 15 l-2.08 0 l0 -0.74 c-0.78 0.58 -1.86 0.94 -2.84 0.94 c-2.84 0 -4.94 -2.18 -4.94 -5.12 z M53.06 15.08 c0 2 1.38 3.44 3.06 3.44 c1.12 0 2.12 -0.52 2.64 -1.58 c0.28 -0.54 0.44 -1.18 0.44 -1.86 s-0.16 -1.32 -0.44 -1.88 c-0.52 -1.06 -1.52 -1.56 -2.64 -1.56 c-1.68 0 -3.06 1.42 -3.06 3.44 z M66.46 18.78 c0 0.8 -0.62 1.42 -1.42 1.42 c-0.78 0 -1.4 -0.62 -1.4 -1.42 c0 -0.76 0.62 -1.38 1.4 -1.38 c0.8 0 1.42 0.62 1.42 1.38 z M73.08 9.92 c2.84 0 3.98 1.72 3.98 3.18 l0 6.9 l-2.06 0 l0 -1.08 c-0.72 0.98 -2 1.26 -2.8 1.26 c-2.26 0 -3.74 -1.32 -3.74 -3.08 c0 -2.46 1.84 -3.34 3.74 -3.34 l2.8 0 l0 -0.66 c0 -0.62 -0.24 -1.48 -1.92 -1.48 c-0.94 0 -1.8 0.5 -2.36 1.28 l-1.42 -1.28 c0.94 -1.04 2.28 -1.7 3.78 -1.7 z M75 16.92 l0 -1.48 l-2.52 0 c-1.22 0 -2.08 0.62 -1.94 1.74 c0.12 0.94 0.88 1.32 1.94 1.32 c1.9 0 2.52 -0.9 2.52 -1.58 z M81.9 10.12 l0 9.88 l-2.06 0 l0 -9.88 l2.06 0 z M82 6.5 c0 0.64 -0.5 1.14 -1.14 1.14 c-0.62 0 -1.12 -0.5 -1.12 -1.14 c0 -0.62 0.5 -1.12 1.12 -1.12 c0.64 0 1.14 0.5 1.14 1.12 z"></path> | |
</g> | |
</svg> | |
</a> | |
<div | |
style=" | |
display: inline-flex; | |
align-items: center; | |
gap: 0.8rem; | |
font-size: 1.75rem; | |
" | |
> | |
<h1 style="font-weight: 900; margin-bottom: 7px;margin-top:5px"> | |
{title} | |
</h1> | |
</div> | |
<p style="margin-bottom: 10px; font-size: 94%; line-height: 23px;"> | |
{desc} | |
There is the <a href="{tutorial_link}"> tutorial </a> | |
</p> | |
</div> | |
""" | |
) | |
examples = [ | |
['女友'], | |
['男友'], | |
['公司最近'], | |
] | |
with gr.Group(): | |
with gr.Row(): | |
with gr.Column(): | |
input_text = gr.Textbox(lines= 10, label="Enter your input text") | |
vc_search = gr.Button("Submit", variant="primary") | |
with gr.Column(): | |
output_text = gr.Textbox(label="Output text") | |
vc_search.click(generate_text, [input_text], [output_text]) | |
with gr.Row(): | |
gr.Examples( | |
examples=examples, | |
inputs=[input_text], | |
outputs=[output_text], | |
fn=generate_text, | |
cache_examples=True, | |
) | |
app.queue() | |
app.launch() | |
except KeyboardInterrupt: | |
app.close() | |
sys.exit(0) | |
if __name__ == '__main__': | |
main() |