Bhaskar2611 commited on
Commit
7a3ae3f
·
verified ·
1 Parent(s): 16cf1e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -21
app.py CHANGED
@@ -1,23 +1,21 @@
1
- import gradio as gr
2
  from huggingface_hub import InferenceClient
 
 
 
 
 
3
 
4
- # Initialize the client with your desired model
5
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
6
 
7
- # Define the system prompt as an AI Dermatologist
8
  def format_prompt(message, history):
9
- prompt = "<s>"
10
- # Start the conversation with a system message
11
- prompt += "[INST] You are an AI Dermatologist designed to assist users with skin and hair care.[/INST]"
12
- for user_prompt, bot_response in history:
13
- prompt += f"[INST] {user_prompt} [/INST]"
14
- prompt += f" {bot_response}</s> "
15
- prompt += f"[INST] {message} [/INST]"
16
- return prompt
17
 
18
- # Function to generate responses with the AI Dermatologist context
19
  def generate(
20
- prompt, history, 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:
@@ -35,9 +33,7 @@ def generate(
35
 
36
  formatted_prompt = format_prompt(prompt, history)
37
 
38
- stream = client.text_generation(
39
- formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False
40
- )
41
  output = ""
42
 
43
  for response in stream:
@@ -45,8 +41,8 @@ def generate(
45
  yield output
46
  return output
47
 
48
- # Customizable input controls for the chatbot interface
49
- additional_inputs = [
50
  gr.Slider(
51
  label="Temperature",
52
  value=0.9,
@@ -85,10 +81,10 @@ additional_inputs = [
85
  )
86
  ]
87
 
88
- # Define the chatbot interface with the starting system message as AI Dermatologist
89
  gr.ChatInterface(
90
  fn=generate,
91
  chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
92
  additional_inputs=additional_inputs,
93
- title="AI Dermatologist"
94
  ).launch(show_api=False)
 
 
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
 
 
9
  def format_prompt(message, history):
10
+ prompt = "<s>"
11
+ for user_prompt, bot_response in history:
12
+ prompt += f"[INST] {user_prompt} [/INST]"
13
+ prompt += f" {bot_response}</s> "
14
+ prompt += f"[INST] {message} [/INST]"
15
+ return prompt
 
 
16
 
 
17
  def generate(
18
+ prompt, history, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
19
  ):
20
  temperature = float(temperature)
21
  if temperature < 1e-2:
 
33
 
34
  formatted_prompt = format_prompt(prompt, history)
35
 
36
+ stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
 
 
37
  output = ""
38
 
39
  for response in stream:
 
41
  yield output
42
  return output
43
 
44
+
45
+ additional_inputs=[
46
  gr.Slider(
47
  label="Temperature",
48
  value=0.9,
 
81
  )
82
  ]
83
 
84
+
85
  gr.ChatInterface(
86
  fn=generate,
87
  chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
88
  additional_inputs=additional_inputs,
89
+ title="""Chatbot"""
90
  ).launch(show_api=False)