Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForCausalLM
3
- import transformers
4
  import torch
5
 
6
  model = AutoModelForCausalLM.from_pretrained(
@@ -9,12 +8,11 @@ model = AutoModelForCausalLM.from_pretrained(
9
  trust_remote_code=True,
10
  device_map="auto",
11
  low_cpu_mem_usage=True,
12
- #offload_folder="/model_files",
13
  )
14
  tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-7b-instruct")
15
 
16
 
17
- def create_embedding(input_text):
18
  input_ids = tokenizer.encode(input_text, return_tensors="pt")
19
  attention_mask = torch.ones(input_ids.shape)
20
 
@@ -30,11 +28,14 @@ def create_embedding(input_text):
30
 
31
  output_text = tokenizer.decode(output[0], skip_special_tokens=True)
32
  print(output_text)
33
- return output_text
34
 
 
 
 
35
 
36
- instructor_model_embeddings = gr.Interface(
37
- fn=create_embedding,
 
38
  inputs=[
39
  gr.inputs.Textbox(label="Input Text"),
40
  ],
 
1
  import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForCausalLM
 
3
  import torch
4
 
5
  model = AutoModelForCausalLM.from_pretrained(
 
8
  trust_remote_code=True,
9
  device_map="auto",
10
  low_cpu_mem_usage=True,
 
11
  )
12
  tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-7b-instruct")
13
 
14
 
15
+ def generate_text(input_text):
16
  input_ids = tokenizer.encode(input_text, return_tensors="pt")
17
  attention_mask = torch.ones(input_ids.shape)
18
 
 
28
 
29
  output_text = tokenizer.decode(output[0], skip_special_tokens=True)
30
  print(output_text)
 
31
 
32
+ # Remove Prompt Echo from Generated Text
33
+ cleaned_output_text = output_text.replace(input_text, "")
34
+ return cleaned_output_text
35
 
36
+
37
+ text_generation_interface = gr.Interface(
38
+ fn=generate_text,
39
  inputs=[
40
  gr.inputs.Textbox(label="Input Text"),
41
  ],