LlamaReviews / app.py
teragron's picture
Update app.py
ed5c215
raw
history blame
1.84 kB
import subprocess
import gradio as gr
#model_file = "best_model_4800it_40M.bin"
model_list = ["best_model_4800it_40M.bin", "model_2200.bin", "model_4200.bin", "model_2200_tr_corpus.bin", "model_8k.bin", "model_1600.bin", "model_3600.bin"]
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()