code: def build_generator(
      model,
      tokenizer,
      temperature=0.6,
      top_p=0.9,
      max_gen_len=4096,
      use_cache=True,
  ):
      def response(material, question):
          if material is None:
              return "Only support txt file."
  
          if not material.name.split(".")[-1] == "txt":
              return "Only support txt file."
  
          material = read_txt_file(material.name)
          prompt_no_input = PROMPT_DICT["prompt_no_input_llama2"]
          prompt = prompt_no_input.format_map(
              {"instruction": material + "\n%s" % question}
          )
  
          inputs = tokenizer(prompt, return_tensors="pt").to(
              model.device
          )
  
          if len(inputs["input_ids"][0]) > 32768:
              return (
                  "This demo supports tokens less than 32768, while the current is %d. Please use material with less tokens."
                  % len(inputs["input_ids"][0])
              )
          torch.cuda.empty_cache()
  
          streamer = TextIteratorStreamer(
              tokenizer, skip_prompt=True, skip_special_tokens=True
          )
          generate_kwargs = dict(
              **inputs,
              max_new_tokens=max_gen_len,
              temperature=temperature,
              top_p=top_p,
              use_cache=use_cache,
              streamer=streamer,
          )
  
          t = Thread(target=model.generate, kwargs=generate_kwargs)
          t.start()
  
          generated_text = ""
          for new_text in streamer:
              generated_text += new_text
              yield generated_text
          return generated_text
  
      return response
  
file_path: long-lora/demo.py
imports: import os
  import sys
  import math
  import torch
  import argparse
  import textwrap
  import transformers
  from peft import PeftModel
  from transformers import GenerationConfig, TextIteratorStreamer
  from llama_attn_replace import replace_llama_attn
  from threading import Thread
  import gradio
label_desc: Use image node_id 3 for calling a global function with example usage: build_generator(model, tokenizer, temperature, top_p, max_gen_len, use_cache) and returns: response, generated_text, str, str, unknown