File size: 908 Bytes
c7eecb3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import gradio as gr
import subprocess
import sys
import os


async def generate(prompt):
    # os.environ["PROMPT"] = prompt
    # stream stout
    process = subprocess.Popen(
        ["mojo", "llama2.mojo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
    )
    text = ""
    for char in iter(lambda: process.stdout.read(1), b""):
        char_decoded = char.decode()
        sys.stdout.write(char_decoded)
        text += char_decoded
        yield text


output_text = gr.Textbox(label="Generated Text")

demo = gr.Interface(
    fn=generate,
    inputs=None,
    outputs=output_text,
    description="""
# llama2.🔥
## [Mojo](https://docs.modular.com/mojo/) implementation of [llama2.c](https://github.com/karpathy/llama2.c) by [@tairov](https://github.com/tairov)
Source: https://github.com/tairov/llama2.mojo
    """,
    allow_flagging="never",
)

demo.queue()
demo.launch(server_name="0.0.0.0")