Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,14 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
|
|
3 |
|
4 |
-
|
5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
-
"""
|
7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
|
|
|
|
9 |
|
|
|
10 |
def respond(
|
11 |
message,
|
12 |
history: list[tuple[str, str]],
|
@@ -39,26 +41,39 @@ def respond(
|
|
39 |
response += token
|
40 |
yield response
|
41 |
|
|
|
|
|
|
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
50 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
51 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
52 |
-
gr.Slider(
|
53 |
-
minimum=0.1,
|
54 |
-
maximum=1.0,
|
55 |
-
value=0.95,
|
56 |
-
step=0.05,
|
57 |
-
label="Top-p (nucleus sampling)",
|
58 |
-
),
|
59 |
],
|
|
|
|
|
|
|
|
|
|
|
60 |
)
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
|
|
63 |
if __name__ == "__main__":
|
64 |
demo.launch()
|
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
+
from transformers import pipeline
|
4 |
|
5 |
+
# Initialize the InferenceClient with the Zephyr model
|
|
|
|
|
6 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
7 |
|
8 |
+
# Use a pipeline for the ParlBERT model for fill-mask
|
9 |
+
mask_pipe = pipeline("fill-mask", model="InfAI/parlbert-german-law")
|
10 |
|
11 |
+
# Define the function for chat completion
|
12 |
def respond(
|
13 |
message,
|
14 |
history: list[tuple[str, str]],
|
|
|
41 |
response += token
|
42 |
yield response
|
43 |
|
44 |
+
# Function to handle mask filling
|
45 |
+
def fill_mask_function(text):
|
46 |
+
return mask_pipe(text)
|
47 |
|
48 |
+
# Create the Gradio interface
|
49 |
+
demo = gr.Interface(
|
50 |
+
fn=respond,
|
51 |
+
inputs=[
|
52 |
+
gr.Textbox(label="Enter your message"),
|
53 |
+
gr.State(), # History
|
54 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
55 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
56 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
57 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
],
|
59 |
+
outputs=[
|
60 |
+
gr.Textbox(label="Response"),
|
61 |
+
],
|
62 |
+
title="Zephyr and ParlBERT Chatbot",
|
63 |
+
description="This chatbot uses Zephyr-7B model and ParlBERT (German Law) for conversation and masked word predictions."
|
64 |
)
|
65 |
|
66 |
+
# Create a separate Gradio interface for the fill-mask model
|
67 |
+
mask_demo = gr.Interface(
|
68 |
+
fn=fill_mask_function,
|
69 |
+
inputs=gr.Textbox(label="Input text with [MASK] token"),
|
70 |
+
outputs=gr.JSON(label="Model output"),
|
71 |
+
live=True,
|
72 |
+
title="InfAI ParlBERT - German Law",
|
73 |
+
description="Enter a sentence with a [MASK] token to get predictions from the InfAI ParlBERT model trained on German law text."
|
74 |
+
)
|
75 |
|
76 |
+
# Launch both interfaces
|
77 |
if __name__ == "__main__":
|
78 |
demo.launch()
|
79 |
+
mask_demo.launch()
|