Silvers-145 commited on
Commit
d92103a
1 Parent(s): be91cb0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -31
app.py CHANGED
@@ -1,12 +1,14 @@
1
  from huggingface_hub import InferenceClient
2
  import gradio as gr
 
 
 
3
 
4
  client = InferenceClient(
5
- # "mistralai/Mixtral-8x7B-Instruct-v0.1"
6
  "Silvers-145/mistral_instruct_generation"
7
- )
8
 
9
- # system_prompt = "Your name is S2 Bot and you work for the company name S2. You have to give answer to the user in rude way"
10
 
11
  def format_prompt(message, history):
12
  prompt = "<s>"
@@ -16,9 +18,7 @@ def format_prompt(message, history):
16
  prompt += f"[INST] {message} [/INST]"
17
  return prompt
18
 
19
- def generate(
20
- prompt, history, system_prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
21
- ):
22
  temperature = float(temperature)
23
  if temperature < 1e-2:
24
  temperature = 1e-2
@@ -30,10 +30,11 @@ def generate(
30
  top_p=top_p,
31
  repetition_penalty=repetition_penalty,
32
  do_sample=True,
33
- seed=42,
34
  )
35
 
36
- formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
 
37
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
38
  output = ""
39
 
@@ -44,11 +45,6 @@ def generate(
44
 
45
 
46
  additional_inputs=[
47
- gr.Textbox(
48
- label="System Prompt",
49
- max_lines=1,
50
- interactive=True,
51
- ),
52
  gr.Slider(
53
  label="Temperature",
54
  value=0.9,
@@ -60,9 +56,9 @@ additional_inputs=[
60
  ),
61
  gr.Slider(
62
  label="Max new tokens",
63
- value=256,
64
- minimum=0,
65
- maximum=1048,
66
  step=64,
67
  interactive=True,
68
  info="The maximum numbers of new tokens",
@@ -87,19 +83,17 @@ additional_inputs=[
87
  )
88
  ]
89
 
90
- examples=[["I'm planning a vacation to Japan. Can you suggest a one-week itinerary including must-visit places and local cuisines to try?", None, None, None, None, None, ],
91
- ["Can you write a short story about a time-traveling detective who solves historical mysteries?", None, None, None, None, None,],
92
- ["I'm trying to learn French. Can you provide some common phrases that would be useful for a beginner, along with their pronunciations?", None, None, None, None, None,],
93
- ["I have chicken, rice, and bell peppers in my kitchen. Can you suggest an easy recipe I can make with these ingredients?", None, None, None, None, None,],
94
- ["Can you explain how the QuickSort algorithm works and provide a Python implementation?", None, None, None, None, None,],
95
- ["What are some unique features of Rust that make it stand out compared to other systems programming languages like C++?", None, None, None, None, None,],
96
- ]
 
 
 
 
 
97
 
98
- gr.ChatInterface(
99
- fn=generate,
100
- chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
101
- additional_inputs=additional_inputs,
102
- title="Mixtral 46.7B",
103
- examples=examples,
104
- concurrency_limit=20,
105
- ).launch(show_api=False)
 
1
  from huggingface_hub import InferenceClient
2
  import gradio as gr
3
+ import random
4
+
5
+ API_URL = "https://api-inference.huggingface.co/models/"
6
 
7
  client = InferenceClient(
8
+ # "mistralai/Mistral-7B-Instruct-v0.1"
9
  "Silvers-145/mistral_instruct_generation"
 
10
 
11
+ )
12
 
13
  def format_prompt(message, history):
14
  prompt = "<s>"
 
18
  prompt += f"[INST] {message} [/INST]"
19
  return prompt
20
 
21
+ def generate(prompt, history, temperature=0.9, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0):
 
 
22
  temperature = float(temperature)
23
  if temperature < 1e-2:
24
  temperature = 1e-2
 
30
  top_p=top_p,
31
  repetition_penalty=repetition_penalty,
32
  do_sample=True,
33
+ seed=random.randint(0, 10**7),
34
  )
35
 
36
+ formatted_prompt = format_prompt(prompt, history)
37
+
38
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
39
  output = ""
40
 
 
45
 
46
 
47
  additional_inputs=[
 
 
 
 
 
48
  gr.Slider(
49
  label="Temperature",
50
  value=0.9,
 
56
  ),
57
  gr.Slider(
58
  label="Max new tokens",
59
+ value=512,
60
+ minimum=64,
61
+ maximum=1024,
62
  step=64,
63
  interactive=True,
64
  info="The maximum numbers of new tokens",
 
83
  )
84
  ]
85
 
86
+ customCSS = """
87
+ #component-7 { # this is the default element ID of the chat component
88
+ height: 800px; # adjust the height as needed
89
+ flex-grow: 1;
90
+ }
91
+ """
92
+
93
+ with gr.Blocks(css=customCSS) as demo:
94
+ gr.ChatInterface(
95
+ generate,
96
+ additional_inputs=additional_inputs,
97
+ )
98
 
99
+ demo.queue().launch(debug=True)