SantiagoTesla commited on
Commit
b806fbd
·
1 Parent(s): 3754e71

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -93
app.py CHANGED
@@ -7,108 +7,22 @@ file_name = "mpt-7b-instruct-q5_1-ggjt.bin"
7
  session_config = SessionConfig(threads=2,batch_size=2)
8
  model = AutoModel.from_pretrained(repo_name, model_file=file_name, session_config=session_config,verbose=True)
9
 
10
- def process_stream(instruction, temperature, top_p, top_k, max_new_tokens, seed):
11
 
12
  prompt=f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
13
  ### Instruction:
14
  {instruction}
15
  ### Response:
16
  Answer:"""
17
- generation_config = GenerationConfig(seed=seed,temperature=temperature,top_p=top_p,top_k=top_k,max_new_tokens=max_new_tokens)
18
  response = ""
19
  streamer = model.stream(prompt=prompt,generation_config=generation_config)
20
  for new_text in streamer:
21
  response += new_text
22
  yield response
 
 
23
 
24
-
25
- with gr.Blocks(
26
- theme=gr.themes.Soft(),
27
- css=".disclaimer {font-variant-caps: all-small-caps;}",
28
- ) as demo:
29
- with gr.Row():
30
- with gr.Column():
31
- with gr.Row():
32
- instruction = gr.Textbox(
33
- placeholder="Enter your question or instruction here",
34
- label="Question/Instruction",
35
- elem_id="q-input",
36
- )
37
- with gr.Accordion("Advanced Options:", open=False):
38
- with gr.Row():
39
- with gr.Column():
40
- with gr.Row():
41
- temperature = gr.Slider(
42
- label="Temperature",
43
- value=0.8,
44
- minimum=0.1,
45
- maximum=1.0,
46
- step=0.1,
47
- interactive=True,
48
- info="Higher values produce more diverse outputs",
49
- )
50
- with gr.Column():
51
- with gr.Row():
52
- top_p = gr.Slider(
53
- label="Top-p (nucleus sampling)",
54
- value=0.95,
55
- minimum=0.0,
56
- maximum=1.0,
57
- step=0.01,
58
- interactive=True,
59
- info=(
60
- "Sample from the smallest possible set of tokens whose cumulative probability "
61
- "exceeds top_p. Set to 1 to disable and sample from all tokens."
62
- ),
63
- )
64
- with gr.Column():
65
- with gr.Row():
66
- top_k = gr.Slider(
67
- label="Top-k",
68
- value=40,
69
- minimum=5,
70
- maximum=80,
71
- step=1,
72
- interactive=True,
73
- info="Sample from a shortlist of top-k tokens — 0 to disable and sample from all tokens.",
74
- )
75
- with gr.Column():
76
- with gr.Row():
77
- max_new_tokens = gr.Slider(
78
- label="Maximum new tokens",
79
- value=256,
80
- minimum=0,
81
- maximum=1024,
82
- step=5,
83
- interactive=True,
84
- info="The maximum number of new tokens to generate",
85
- )
86
-
87
- with gr.Column():
88
- with gr.Row():
89
- seed = gr.Number(
90
- label="Seed",
91
- value=42,
92
- interactive=True,
93
- info="The seed to use for the generation",
94
- precision=0
95
- )
96
- with gr.Row():
97
- submit = gr.Button("Submit")
98
- with gr.Row():
99
- with gr.Box():
100
- gr.Markdown("**Output:**")
101
- output_7b = gr.Markdown()
102
-
103
- submit.click(
104
- process_stream,
105
- inputs=[instruction, temperature, top_p, top_k, max_new_tokens,seed],
106
- outputs=output_7b,
107
- )
108
- instruction.submit(
109
- process_stream,
110
- inputs=[instruction, temperature, top_p, top_k, max_new_tokens,seed],
111
- outputs=output_7b,
112
- )
113
-
114
- demo.queue(max_size=4, concurrency_count=1).launch(debug=True)
 
7
  session_config = SessionConfig(threads=2,batch_size=2)
8
  model = AutoModel.from_pretrained(repo_name, model_file=file_name, session_config=session_config,verbose=True)
9
 
10
+ def process_stream(instruction):
11
 
12
  prompt=f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
13
  ### Instruction:
14
  {instruction}
15
  ### Response:
16
  Answer:"""
17
+ generation_config = GenerationConfig(seed=1.1,temperature=0.1,top_p=0.15,top_k=0,max_new_tokens=1000)
18
  response = ""
19
  streamer = model.stream(prompt=prompt,generation_config=generation_config)
20
  for new_text in streamer:
21
  response += new_text
22
  yield response
23
+ inputs = gr.inputs.Textbox(lines=7, label="Chat with AI")
24
+ outputs = gr.outputs.Textbox(label="Reply")
25
 
26
+ gr.Interface(fn=process_stream, inputs=inputs, outputs=outputs, title="Self_Trained_V2",
27
+ description="Ask anything you want",
28
+ ).launch(share=True)