alamin655 commited on
Commit
fc9f271
·
1 Parent(s): ac6c1b5

Rename inference.py to app.py

Browse files
Files changed (1) hide show
  1. inference.py → app.py +19 -9
inference.py → app.py RENAMED
@@ -1,6 +1,7 @@
1
  import os
2
  from dataclasses import dataclass, asdict
3
  from ctransformers import AutoModelForCausalLM, AutoConfig
 
4
 
5
 
6
  @dataclass
@@ -39,6 +40,14 @@ def generate(
39
  )
40
 
41
 
 
 
 
 
 
 
 
 
42
  if __name__ == "__main__":
43
  config = AutoConfig.from_pretrained(
44
  "teknium/Replit-v2-CodeInstruct-3B", context_length=2048
@@ -59,16 +68,17 @@ if __name__ == "__main__":
59
  reset=True, # reset history (cache)
60
  stream=True, # streaming per word/token
61
  threads=int(os.cpu_count() / 6), # adjust for your CPU
62
- stop=["<|endoftext|>"],
63
  )
64
 
65
  user_prefix = "[user]: "
66
- assistant_prefix = f"[assistant]:"
67
 
68
- while True:
69
- user_prompt = input(user_prefix)
70
- generator = generate(llm, generation_config, user_prompt.strip())
71
- print(assistant_prefix, end=" ", flush=True)
72
- for word in generator:
73
- print(word, end="", flush=True)
74
- print("")
 
 
1
  import os
2
  from dataclasses import dataclass, asdict
3
  from ctransformers import AutoModelForCausalLM, AutoConfig
4
+ import gradio as gr
5
 
6
 
7
  @dataclass
 
40
  )
41
 
42
 
43
+ def generate_response(user_input):
44
+ generator = generate(llm, generation_config, user_input.strip())
45
+ response = ""
46
+ for word in generator:
47
+ response += word
48
+ return response
49
+
50
+
51
  if __name__ == "__main__":
52
  config = AutoConfig.from_pretrained(
53
  "teknium/Replit-v2-CodeInstruct-3B", context_length=2048
 
68
  reset=True, # reset history (cache)
69
  stream=True, # streaming per word/token
70
  threads=int(os.cpu_count() / 6), # adjust for your CPU
71
+ stop=[""],
72
  )
73
 
74
  user_prefix = "[user]: "
75
+ assistant_prefix = f"[assistant]: "
76
 
77
+ iface = gr.Interface(
78
+ fn=generate_response,
79
+ inputs=gr.inputs.Textbox(label=user_prefix),
80
+ outputs=gr.outputs.Textbox(label=assistant_prefix),
81
+ title="Chat with Assistant",
82
+ description="Ask any question and get a response from the Assistant!",
83
+ )
84
+ iface.launch()