Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,85 +1,116 @@
|
|
1 |
-
# import gradio as gr
|
2 |
# from huggingface_hub import InferenceClient
|
|
|
3 |
|
4 |
-
#
|
5 |
-
#
|
6 |
-
#
|
7 |
-
# client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
-
|
9 |
-
|
10 |
-
# def respond(
|
11 |
-
# message,
|
12 |
-
# history: list[tuple[str, str]],
|
13 |
-
# system_message,
|
14 |
-
# max_tokens,
|
15 |
-
# temperature,
|
16 |
-
# top_p,
|
17 |
-
# ):
|
18 |
-
# messages = [{"role": "system", "content": system_message}]
|
19 |
|
20 |
-
# for val in history:
|
21 |
-
# if val[0]:
|
22 |
-
# messages.append({"role": "user", "content": val[0]})
|
23 |
-
# if val[1]:
|
24 |
-
# messages.append({"role": "assistant", "content": val[1]})
|
25 |
|
26 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
#
|
31 |
-
# messages,
|
32 |
-
# max_tokens=max_tokens,
|
33 |
-
# stream=True,
|
34 |
# temperature=temperature,
|
|
|
35 |
# top_p=top_p,
|
36 |
-
#
|
37 |
-
#
|
38 |
-
|
39 |
-
#
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
#
|
44 |
-
#
|
45 |
-
|
46 |
-
#
|
47 |
-
#
|
48 |
-
#
|
49 |
-
#
|
50 |
-
|
51 |
-
|
52 |
-
#
|
53 |
-
#
|
54 |
-
#
|
55 |
-
#
|
56 |
-
#
|
57 |
-
#
|
58 |
-
#
|
59 |
-
#
|
60 |
-
#
|
61 |
-
|
62 |
-
|
63 |
-
#
|
64 |
-
#
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
import gradio as gr
|
|
|
67 |
|
68 |
-
client
|
69 |
-
|
70 |
-
)
|
71 |
-
|
72 |
|
|
|
73 |
def format_prompt(message, history):
|
74 |
-
|
75 |
-
|
76 |
-
prompt +=
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
81 |
def generate(
|
82 |
-
prompt, history, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0
|
83 |
):
|
84 |
temperature = float(temperature)
|
85 |
if temperature < 1e-2:
|
@@ -97,7 +128,9 @@ def generate(
|
|
97 |
|
98 |
formatted_prompt = format_prompt(prompt, history)
|
99 |
|
100 |
-
stream = client.text_generation(
|
|
|
|
|
101 |
output = ""
|
102 |
|
103 |
for response in stream:
|
@@ -105,8 +138,8 @@ def generate(
|
|
105 |
yield output
|
106 |
return output
|
107 |
|
108 |
-
|
109 |
-
additional_inputs=[
|
110 |
gr.Slider(
|
111 |
label="Temperature",
|
112 |
value=0.9,
|
@@ -145,13 +178,13 @@ additional_inputs=[
|
|
145 |
)
|
146 |
]
|
147 |
|
148 |
-
|
149 |
gr.ChatInterface(
|
150 |
fn=generate,
|
151 |
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, layout="panel"),
|
152 |
additional_inputs=additional_inputs,
|
153 |
-
title="
|
154 |
).launch(show_api=False)
|
155 |
|
156 |
-
|
157 |
-
gr.load("models/Bhaskar2611/Capstone").launch()
|
|
|
|
|
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:
|
22 |
+
# temperature = 1e-2
|
23 |
+
# top_p = float(top_p)
|
24 |
|
25 |
+
# generate_kwargs = dict(
|
|
|
|
|
|
|
26 |
# temperature=temperature,
|
27 |
+
# max_new_tokens=max_new_tokens,
|
28 |
# top_p=top_p,
|
29 |
+
# repetition_penalty=repetition_penalty,
|
30 |
+
# do_sample=True,
|
31 |
+
# seed=42,
|
32 |
+
# )
|
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:
|
40 |
+
# output += response.token.text
|
41 |
+
# yield output
|
42 |
+
# return output
|
43 |
+
|
44 |
+
|
45 |
+
# additional_inputs=[
|
46 |
+
# gr.Slider(
|
47 |
+
# label="Temperature",
|
48 |
+
# value=0.9,
|
49 |
+
# minimum=0.0,
|
50 |
+
# maximum=1.0,
|
51 |
+
# step=0.05,
|
52 |
+
# interactive=True,
|
53 |
+
# info="Higher values produce more diverse outputs",
|
54 |
+
# ),
|
55 |
+
# gr.Slider(
|
56 |
+
# label="Max new tokens",
|
57 |
+
# value=256,
|
58 |
+
# minimum=0,
|
59 |
+
# maximum=1048,
|
60 |
+
# step=64,
|
61 |
+
# interactive=True,
|
62 |
+
# info="The maximum numbers of new tokens",
|
63 |
+
# ),
|
64 |
+
# gr.Slider(
|
65 |
+
# label="Top-p (nucleus sampling)",
|
66 |
+
# value=0.90,
|
67 |
+
# minimum=0.0,
|
68 |
+
# maximum=1,
|
69 |
+
# step=0.05,
|
70 |
+
# interactive=True,
|
71 |
+
# info="Higher values sample more low-probability tokens",
|
72 |
+
# ),
|
73 |
+
# gr.Slider(
|
74 |
+
# label="Repetition penalty",
|
75 |
+
# value=1.2,
|
76 |
+
# minimum=1.0,
|
77 |
+
# maximum=2.0,
|
78 |
+
# step=0.05,
|
79 |
+
# interactive=True,
|
80 |
+
# info="Penalize repeated tokens",
|
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, layout="panel"),
|
88 |
+
# additional_inputs=additional_inputs,
|
89 |
+
# title="""AI Dermatologist"""
|
90 |
+
# ).launch(show_api=False)
|
91 |
+
|
92 |
+
|
93 |
+
# gr.load("models/Bhaskar2611/Capstone").launch()
|
94 |
import gradio as gr
|
95 |
+
from huggingface_hub import InferenceClient
|
96 |
|
97 |
+
# Initialize the client with your desired model
|
98 |
+
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
|
|
|
|
99 |
|
100 |
+
# Define the system prompt as an AI Dermatologist
|
101 |
def format_prompt(message, history):
|
102 |
+
prompt = "<s>"
|
103 |
+
# Start the conversation with a system message
|
104 |
+
prompt += "[INST] You are an AI Dermatologist designed to assist users with skin and hair care.[/INST]"
|
105 |
+
for user_prompt, bot_response in history:
|
106 |
+
prompt += f"[INST] {user_prompt} [/INST]"
|
107 |
+
prompt += f" {bot_response}</s> "
|
108 |
+
prompt += f"[INST] {message} [/INST]"
|
109 |
+
return prompt
|
110 |
+
|
111 |
+
# Function to generate responses with the AI Dermatologist context
|
112 |
def generate(
|
113 |
+
prompt, history, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0
|
114 |
):
|
115 |
temperature = float(temperature)
|
116 |
if temperature < 1e-2:
|
|
|
128 |
|
129 |
formatted_prompt = format_prompt(prompt, history)
|
130 |
|
131 |
+
stream = client.text_generation(
|
132 |
+
formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False
|
133 |
+
)
|
134 |
output = ""
|
135 |
|
136 |
for response in stream:
|
|
|
138 |
yield output
|
139 |
return output
|
140 |
|
141 |
+
# Customizable input controls for the chatbot interface
|
142 |
+
additional_inputs = [
|
143 |
gr.Slider(
|
144 |
label="Temperature",
|
145 |
value=0.9,
|
|
|
178 |
)
|
179 |
]
|
180 |
|
181 |
+
# Define the chatbot interface with the starting system message as AI Dermatologist
|
182 |
gr.ChatInterface(
|
183 |
fn=generate,
|
184 |
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, layout="panel"),
|
185 |
additional_inputs=additional_inputs,
|
186 |
+
title="AI Dermatologist"
|
187 |
).launch(show_api=False)
|
188 |
|
189 |
+
# Load your model after launching the interface
|
190 |
+
gr.load("models/Bhaskar2611/Capstone").launch()
|