Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,50 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
-
|
4 |
client = InferenceClient("thviet79/model-QA-medical")
|
5 |
|
6 |
-
|
7 |
-
message,
|
8 |
-
history: list[tuple[str, str]],
|
9 |
-
system_message,
|
10 |
-
max_tokens,
|
11 |
-
temperature,
|
12 |
-
top_p,
|
13 |
-
):
|
14 |
-
messages = [{"role": "system", "content": system_message}]
|
15 |
-
|
16 |
-
for val in history:
|
17 |
-
if val[0]:
|
18 |
-
messages.append({"role": "user", "content": val[0]})
|
19 |
-
if val[1]:
|
20 |
-
messages.append({"role": "assistant", "content": val[1]})
|
21 |
-
|
22 |
-
messages.append({"role": "user", "content": message})
|
23 |
-
|
24 |
-
# Here, call the Hugging Face Inference API with the messages and other parameters
|
25 |
-
response = client.text_generation(
|
26 |
-
model="thviet79/model-QA-medical",
|
27 |
-
inputs=messages,
|
28 |
-
parameters={"max_tokens": max_tokens, "temperature": temperature, "top_p": top_p},
|
29 |
-
)
|
30 |
-
return response["generated_text"] # Extract the model's response
|
31 |
-
|
32 |
-
demo = gr.ChatInterface(
|
33 |
-
respond,
|
34 |
-
additional_inputs=[
|
35 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
36 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
37 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
38 |
-
gr.Slider(
|
39 |
-
minimum=0.1,
|
40 |
-
maximum=1.0,
|
41 |
-
value=0.95,
|
42 |
-
step=0.05,
|
43 |
-
label="Top-p (nucleus sampling)",
|
44 |
-
),
|
45 |
-
],
|
46 |
-
type='messages' # This makes it use the OpenAI-style structure
|
47 |
-
)
|
48 |
-
|
49 |
-
if __name__ == "__main__":
|
50 |
-
demo.launch(share = True)
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
|
|
3 |
client = InferenceClient("thviet79/model-QA-medical")
|
4 |
|
5 |
+
client.question_answering(question="Hi?")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|