mrbeliever commited on
Commit
6ec4fc2
1 Parent(s): 763bcbd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -13
app.py CHANGED
@@ -1,14 +1,12 @@
1
  from huggingface_hub import InferenceClient
2
  import gradio as gr
3
 
4
- client = InferenceClient(
5
- "mistralai/Mistral-7B-Instruct-v0.3"
6
- )
7
 
8
  # Your system prompt
9
  SYSTEM_PROMPT = "Your goal is to create engaging, authentic, and contextually appropriate captions for social media platforms. The captions should captivate the audience without being cringe-worthy, ensuring they resonate well with diverse demographics."
10
 
11
- def format_prompt(message, history):
12
  prompt = "<s>"
13
  prompt += f"[INST] SYSTEM: {SYSTEM_PROMPT} [/INST]" # Add the system prompt here
14
  for user_prompt, bot_response in history:
@@ -17,9 +15,7 @@ def format_prompt(message, history):
17
  prompt += f"[INST] {message} [/INST]"
18
  return prompt
19
 
20
- def generate(
21
- prompt, history=[], temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
22
- ):
23
  temperature = float(temperature)
24
  if temperature < 1e-2:
25
  temperature = 1e-2
@@ -34,7 +30,7 @@ def generate(
34
  seed=42,
35
  )
36
 
37
- formatted_prompt = format_prompt(prompt, history)
38
 
39
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
40
  output = ""
@@ -46,12 +42,9 @@ def generate(
46
 
47
  iface = gr.Interface(
48
  fn=generate,
49
- inputs=[
50
- gr.Textbox(placeholder="Enter your prompt here...", lines=2, max_lines=2, label=""),
51
- gr.Button("Generate")
52
- ],
53
  outputs=gr.Textbox(label="Output", interactive=True, lines=10),
54
- layout="vertical"
55
  )
56
 
57
  iface.launch()
 
1
  from huggingface_hub import InferenceClient
2
  import gradio as gr
3
 
4
+ client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
 
 
5
 
6
  # Your system prompt
7
  SYSTEM_PROMPT = "Your goal is to create engaging, authentic, and contextually appropriate captions for social media platforms. The captions should captivate the audience without being cringe-worthy, ensuring they resonate well with diverse demographics."
8
 
9
+ def format_prompt(message, history=[]):
10
  prompt = "<s>"
11
  prompt += f"[INST] SYSTEM: {SYSTEM_PROMPT} [/INST]" # Add the system prompt here
12
  for user_prompt, bot_response in history:
 
15
  prompt += f"[INST] {message} [/INST]"
16
  return prompt
17
 
18
+ def generate(prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
 
 
19
  temperature = float(temperature)
20
  if temperature < 1e-2:
21
  temperature = 1e-2
 
30
  seed=42,
31
  )
32
 
33
+ formatted_prompt = format_prompt(prompt)
34
 
35
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
36
  output = ""
 
42
 
43
  iface = gr.Interface(
44
  fn=generate,
45
+ inputs=gr.Textbox(placeholder="Enter your prompt here...", lines=2, max_lines=2, label="Prompt"),
 
 
 
46
  outputs=gr.Textbox(label="Output", interactive=True, lines=10),
47
+ live=True,
48
  )
49
 
50
  iface.launch()