File size: 2,053 Bytes
ba73aa3
001ccce
 
 
ba73aa3
 
 
001ccce
ba73aa3
 
 
 
 
 
 
 
 
 
47f1329
001ccce
 
 
 
 
 
 
47f1329
 
001ccce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ed5c215
001ccce
 
 
 
47f1329
001ccce
 
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import subprocess
import gradio as gr

def list_bin_files():
    # Get the current directory
    current_directory = os.getcwd()

    # List all files in the current directory
    all_files = os.listdir(current_directory)

    # Filter files with the ".bin" extension
    bin_files = [file for file in all_files if file.endswith(".bin")]

    return bin_files

# Call the function to get the list of ".bin" files
model_list = list_bin_files()

try:
    subprocess.run(["make", "runfast"], check=True, shell=True)
    print("Model compilation successful.")
except subprocess.CalledProcessError as e:
    print("Error:", e)
    print(e.stderr)

def chatbot(prompt, temperature, topt, maxtoken, model):
    command = ["./run", model, "-t", str(temperature), "-p", str(topt), "-n", str(maxtoken), "-i", f"{prompt}"]
    try:
        result = subprocess.run(command, capture_output=True, text=True, check=True, shell=False)
        response = result.stdout
    except subprocess.CalledProcessError as e:
        response = "Error occurred while processing the request."
    return response

with gr.Blocks() as demo:
    gr.Markdown("HF Spaces for Product Review Writer")
    with gr.Row():
        with gr.Column():
            inp = gr.Textbox(placeholder="Type the title of the product Review")
            with gr.Row():
                with gr.Column():
                    temperature_slider = gr.Slider(minimum=0.1, maximum=2.0, value=0.8, label="Temperature")
                    topt_slider = gr.Slider(minimum=0.1, maximum=1.0, value=0.9, label="Topt")
                    maxtoken_slider = gr.Slider(minimum=64, maximum=1024, value=256, label="Max Tokens")
                    model_pick = gr.Dropdown(model_list, label="Model", info="Model")
        out = gr.Textbox()
        
    btn = gr.Button("Run")
    gr.Examples(examples=[["best sci-fi book ever"], ["great laptop for the price"]], inputs=[inp])
    btn.click(fn=chatbot, inputs=[inp, temperature_slider, topt_slider, maxtoken_slider, model_pick], outputs=out)


demo.launch()