karthik18AI commited on
Commit
5de9a55
·
verified ·
1 Parent(s): 09777ea
Files changed (1) hide show
  1. app.py +13 -20
app.py CHANGED
@@ -1,15 +1,7 @@
1
  from huggingface_hub import InferenceClient
2
- import gradio as gr
3
-
4
- css = '''
5
- .gradio-container{max-width: 1000px !important}
6
- h1{text-align:center}
7
- footer {
8
- visibility: hidden
9
- }
10
- '''
11
 
12
  client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
 
13
  def format_prompt(message, history, system_prompt=None):
14
  prompt = "<s>"
15
  for user_prompt, bot_response in history:
@@ -19,7 +11,7 @@ def format_prompt(message, history, system_prompt=None):
19
  prompt += f"[SYS] {system_prompt} [/SYS]"
20
  prompt += f"[INST] {message} [/INST]"
21
  return prompt
22
- #Generate
23
  def generate(
24
  prompt, history, system_prompt=None, temperature=0.2, max_new_tokens=1024, top_p=0.95, repetition_penalty=1.0,
25
  ):
@@ -44,15 +36,16 @@ def generate(
44
 
45
  for response in stream:
46
  output += response.token.text
47
- yield output
48
  return output
49
 
50
-
51
- demo = gr.ChatInterface(
52
- fn=generate,
53
- css=css,
54
- title="",
55
- theme="bethecloud/storj_theme"
56
- )
57
-
58
- demo.queue().launch(show_api=False)
 
 
1
  from huggingface_hub import InferenceClient
 
 
 
 
 
 
 
 
 
2
 
3
  client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
4
+
5
  def format_prompt(message, history, system_prompt=None):
6
  prompt = "<s>"
7
  for user_prompt, bot_response in history:
 
11
  prompt += f"[SYS] {system_prompt} [/SYS]"
12
  prompt += f"[INST] {message} [/INST]"
13
  return prompt
14
+
15
  def generate(
16
  prompt, history, system_prompt=None, temperature=0.2, max_new_tokens=1024, top_p=0.95, repetition_penalty=1.0,
17
  ):
 
36
 
37
  for response in stream:
38
  output += response.token.text
39
+ print(output, end='', flush=True)
40
  return output
41
 
42
+ if __name__ == "__main__":
43
+ history = []
44
+ system_prompt = None
45
+ while True:
46
+ user_input = input("You: ")
47
+ if user_input.lower() in ["exit", "quit"]:
48
+ break
49
+ response = generate(user_input, history, system_prompt)
50
+ history.append((user_input, response))
51
+ print(f"\nBot: {response}\n")