File size: 1,043 Bytes
8eeb5e9
613e5d1
 
 
 
511db5e
 
 
 
613e5d1
511db5e
 
 
 
613e5d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()
    
    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 translation

iface = gr.Interface(
    fn=generate_text, 
    inputs=[], 
    outputs="text", 
    submit_label="开始生成", 
    title="和小羊驼一起玩"
)
iface.launch()