Mykes commited on
Commit
fa14f0d
1 Parent(s): 50b8ae0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -28
app.py CHANGED
@@ -18,36 +18,47 @@ def respond(
18
  temperature,
19
  top_p,
20
  ):
21
- # ... (rest of the respond function remains the same)
 
 
 
 
 
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  # Create the Gradio interface
24
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
25
- gr.Markdown("# Med TinyLlama Chat")
26
- gr.Markdown("Chat with the Med TinyLlama model for medical information.")
27
-
28
- chatbot = gr.Chatbot(height=300)
29
- msg = gr.Textbox(label="Type your message here", placeholder="Ask a medical question...")
30
-
31
- with gr.Accordion("Advanced Options", open=False):
32
- system_message = gr.Textbox(value="", label="System message")
33
- max_tokens = gr.Slider(minimum=128, maximum=4096, value=2048, step=1, label="Max new tokens")
34
- temperature = gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature")
35
- top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.9, step=0.05, label="Top-p (nucleus sampling)")
36
-
37
- submit_btn = gr.Button("Send")
38
- clear_btn = gr.Button("Clear")
39
-
40
- submit_btn.click(
41
- respond,
42
- inputs=[msg, chatbot, system_message, max_tokens, temperature, top_p],
43
- outputs=[chatbot],
44
- )
45
- msg.submit(
46
- respond,
47
- inputs=[msg, chatbot, system_message, max_tokens, temperature, top_p],
48
- outputs=[chatbot],
49
- )
50
- clear_btn.click(lambda: None, None, chatbot, queue=False)
51
 
52
  if __name__ == "__main__":
53
  demo.launch()
 
18
  temperature,
19
  top_p,
20
  ):
21
+ history = history[-3:]
22
+ # Construct the prompt
23
+ prompt = f"<s>{system_message}\n\n"
24
+ for user_msg, assistant_msg in history:
25
+ prompt += f"<|user|>{user_msg}<|end|></s> <|assistant|>{assistant_msg}<|end|></s>"
26
+ prompt += f"<|user|>{message}<|end|></s> <|assistant|>"
27
 
28
+ # Generate response
29
+ response = ""
30
+ for token in model(
31
+ prompt,
32
+ max_tokens=max_tokens,
33
+ temperature=temperature,
34
+ top_p=top_p,
35
+ stream=True,
36
+ stop=["<|end|>", "</s>"]
37
+ ):
38
+ response += token['choices'][0]['text']
39
+ yield response.strip()
40
+
41
  # Create the Gradio interface
42
+ demo = gr.ChatInterface(
43
+ respond,
44
+ undo_btn="Отменить",
45
+ clear_btn="Очистить",
46
+ additional_inputs=[
47
+ # gr.Textbox(value="You are a friendly medical assistant.", label="System message"),
48
+ gr.Textbox(value="", label="System message"),
49
+ gr.Slider(minimum=128, maximum=4096, value=2048, step=1, label="Max new tokens"),
50
+ gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature"),
51
+ gr.Slider(
52
+ minimum=0.1,
53
+ maximum=1.0,
54
+ value=0.9,
55
+ step=0.05,
56
+ label="Top-p (nucleus sampling)",
57
+ ),
58
+ ],
59
+ title="Med TinyLlama Chat",
60
+ description="Chat with the Med TinyLlama model for medical information.",
61
+ )
 
 
 
 
 
 
 
62
 
63
  if __name__ == "__main__":
64
  demo.launch()