Monimoy commited on
Commit
92b52b1
·
verified ·
1 Parent(s): 4707ac8

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +13 -4
  2. requirements.txt +4 -1
app.py CHANGED
@@ -1,7 +1,8 @@
1
  import openvino_genai
 
2
  import gradio as gr
3
 
4
- print(" Inside application")
5
  # Base Phi-2 model name
6
  #base_model_name = "microsoft/phi-2"
7
  base_model_name = "Monimoy/openvino_phi2"
@@ -15,7 +16,15 @@ device = 'CPU' # GPU can be used as well
15
  #adapter_config = openvino_genai.AdapterConfig(adapter)
16
  #print(" Inside application3")
17
  #pipe = openvino_genai.LLMPipeline(model=base_model_name, device=device, adapters=adapter_config) # register all required adapters here
18
- pipe = openvino_genai.LLMPipeline(model=base_model_name)
 
 
 
 
 
 
 
 
19
  print(" Inside application4")
20
 
21
  print("Generate with LoRA adapter and alpha set to 0.75:")
@@ -28,8 +37,8 @@ def generate_response(prompt):
28
  #with torch.no_grad():
29
  # output = model.generate(**inputs, max_new_tokens=100, do_sample=True, temperature=0.7)
30
  #return tokenizer.decode(output[0], skip_special_tokens=True)
31
- return pipe.generate(prompt, max_new_tokens=100, adapters=openvino_genai.AdapterConfig(adapter, 0.75))
32
-
33
 
34
  # Define example prompts
35
  examples = [
 
1
  import openvino_genai
2
+ from optimum.intel.openvino import OVModelForCausalLM
3
  import gradio as gr
4
 
5
+ print(" Inside application1")
6
  # Base Phi-2 model name
7
  #base_model_name = "microsoft/phi-2"
8
  base_model_name = "Monimoy/openvino_phi2"
 
16
  #adapter_config = openvino_genai.AdapterConfig(adapter)
17
  #print(" Inside application3")
18
  #pipe = openvino_genai.LLMPipeline(model=base_model_name, device=device, adapters=adapter_config) # register all required adapters here
19
+ #pipe = openvino_genai.LLMPipeline(model=base_model_name)
20
+ # Load model from Hugging Face
21
+ model = OVModelForCausalLM.from_pretrained(base_model_name, export=True)
22
+ print(" Inside application2")
23
+ tokenizer = AutoTokenizer.from_pretrained(base_model_name)
24
+ print(" Inside application3")
25
+
26
+ # Create a pipeline
27
+ text_generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
28
  print(" Inside application4")
29
 
30
  print("Generate with LoRA adapter and alpha set to 0.75:")
 
37
  #with torch.no_grad():
38
  # output = model.generate(**inputs, max_new_tokens=100, do_sample=True, temperature=0.7)
39
  #return tokenizer.decode(output[0], skip_special_tokens=True)
40
+ #return pipe.generate(prompt, max_new_tokens=100, adapters=openvino_genai.AdapterConfig(adapter, 0.75))
41
+ return text_generator(prompt, max_length=50)
42
 
43
  # Define example prompts
44
  examples = [
requirements.txt CHANGED
@@ -1,3 +1,6 @@
1
  gradio
2
  huggingface_hub
3
- openvino-genai
 
 
 
 
1
  gradio
2
  huggingface_hub
3
+ openvino
4
+ openvino-genai
5
+ optimum-intel
6
+ transformers