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.
Enter the beginning of story and click the button
It's just a simplified demo, you can use more advanced features optimize quality
""" tutorial_link = "https://docs.cworld.ai/docs/cworld-ai/quick-start-dcard" gr.HTML( f"""

{title}

{desc} There is the tutorial

""" ) 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()