Spaces:
Build error
Build error
kwabs22 commited on
Commit ·
078637c
1
Parent(s): e3894fb
Testing built in prompt?
Browse files12345678910111213141516171819202122232425262728293031321 unmodified line34353637383940414243444522 unmodified lines68697071727374757677787980import gradio as gr#from llama_cpp import Llamaimport randomimport subprocessimport time# Initialize model#llm = Llama(model_path="/stablelm-2-zephyr-1_6b-Q4_0.gguf", n_gpu_layers=0, seed=random.randint(1, 2**31))"""def generate_response(user_message):encodeduserm = b"### Human: " + user_message.encode('utf-8') + b"\n### Assistant:"tokens = llm.tokenize(encodeduserm)output = b""count = 0for token in llm.generate(tokens, top_k=40, top_p=0.95, temp=0.72, repeat_penalty=1.1):text = llm.detokenize([token])output += textcount += 1if count >= 500 or (token == llm.token_eos()):breakreturn output.decode()""""""def generate_response(user_message):print("Before request")cmd = ["/app/llama.cpp/main", # Path to the executable"-m", "/app/llama.cpp/models/stablelm-2-zephyr-1_6b-Q4_0.gguf",1 unmodified line"-n", "400","-e"]result = subprocess.run(cmd, capture_output=True, text=True)print("After response")return result.stdout"""def generate_response(user_message):cmd = ["/app/llama.cpp/main", # Path to the executable"-m", "/app/llama.cpp/models/stablelm-2-zephyr-1_6b-Q4_0.gguf",22 unmodified lineserror_message = process.stderr.read()print(f"Error: {error_message}")iface = gr.Interface(fn=generate_response,inputs=gr.Textbox(lines=2, placeholder="Type your message here..."),outputs="text",title="LLaMA Chat Interface",description="Enter your message and get a response from the LLaMA model.",flagging_dir="/usr/src/app/flagged",)iface.launch(server_name="0.0.0.0") #share=True)1234567891 unmodified line11121314151617181920212223242526272829303132333435363738394022 unmodified lines636465666768697071727374757677787980818283848586878889import gradio as grimport randomimport subprocessimport timedef generate_response(user_message): #Figure Out the parameters later and find a way to get the ram usagecmd = ["/app/llama.cpp/main", # Path to the executable"-m", "/app/llama.cpp/models/stablelm-2-zephyr-1_6b-Q4_0.gguf",1 unmodified line"-n", "400","-e"]# Start the subprocessprocess = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)start_time = time.time()alllines = ""# Yield each line of output as it becomes availablefor line in process.stdout:alllines += " " + lineelapsed_time = time.time() - start_time # Calculate elapsed timeyield f"{alllines} [Inference time: {elapsed_time:.2f} seconds]"# Wait for the subprocess to finish if it hasn't alreadyprocess.wait()# Check for any errorsif process.returncode != 0:error_message = process.stderr.read()print(f"Error: {error_message}")def custom_generate_response(user_message, builtinprompt): #Figure Out the parameters later and find a way to get the ram usageuser_message = builtinprompt + '\n\n ' + user_messagecmd = ["/app/llama.cpp/main", # Path to the executable"-m", "/app/llama.cpp/models/stablelm-2-zephyr-1_6b-Q4_0.gguf",22 unmodified lineserror_message = process.stderr.read()print(f"Error: {error_message}")CustomPrompts = ["Class Diagram for:""Pydot code for:"]with gr.Blocks() as iface:gr.Interface(fn=generate_response,inputs=gr.Textbox(lines=2, placeholder="Type your message here..."),outputs="text",title="Stable LM 2 Zephyr (1.6b) LLama.cpp Interface Test",description="No Message History for now - Enter your message and get a response.",flagging_dir="/usr/src/app/flagged",)gr.HTML()MainOutput = gr.TextArea()CustomButtonInput = gr.Input()CustomButtonClassDiagram = gr.Button(CustomPrompts[0])CustomButtonPydotcode = gr.Button(CustomPrompts[1])CustomButtonClassDiagram .click(custom_generate_response, inputs=[CustomButtonInput, CustomPrompts[0]], outputs=MainOutput)CustomButtonPydotcode.click(custom_generate_response, inputs=[CustomButtonInput, CustomPrompts[1]], outputs=MainOutput)iface.launch(server_name="0.0.0.0") #share=True)
app.py+46-37