play_with_baby_llama2 / baby_llama2.py
Ritori's picture
Update baby_llama2.py
d7bcd6e
import os
import subprocess
import gradio as gr
from translate import Translator
def compile_c_program():
compile_command = ["gcc", "-o", "run", "run.c"] # replace "source.c" with your C source file
subprocess.check_call(compile_command) # this will raise an error if compilation fails
def generate_text():
# Make sure the C program is compiled before we try to run it
if not os.path.exists("run"):
compile_c_program()
os.chmod('run', 0o755)
cmd = ['./run', 'model.bin']
result = subprocess.run(cmd, stdout=subprocess.PIPE, text=True)
translator= Translator(from_lang='en', to_lang='zh-cn')
# Split the output into sentences
sentences = result.stdout.split('. ')
# Translate each sentence and join them back together
translation = '. '.join(translator.translate(sentence) for sentence in sentences)
return result
iface = gr.Interface(
fn=generate_text,
inputs=[],
outputs="text",
submit_label="开始生成",
title="和小羊驼一起玩"
)
iface.launch(debug=True)