prompt-enhancer / app.py
ayan4m1
use text_generation instead of chat_completion, re-add top-k
49ecfa7
raw
history blame
1.47 kB
import gradio as gr
from huggingface_hub import InferenceClient
"""
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
"""
client = InferenceClient(model="pszemraj/distilgpt2-magicprompt-SD")
def respond(
message,
_: list[tuple[str, str]],
max_tokens: int,
temperature: float,
top_p: float,
top_k: int
):
response = ""
for message in client.text_generation(
message,
max_tokens=max_tokens,
stream=True,
temperature=temperature,
top_p=top_p,
top_k=top_k
):
token = message.choices[0].delta.content
response += token
yield response
"""
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
"""
demo = gr.ChatInterface(
respond,
additional_inputs=[
gr.Slider(minimum=8, maximum=128, value=64, step=8, label="Max tokens"),
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
gr.Slider(
minimum=0.1,
maximum=1.0,
value=0.95,
step=0.05,
label="Top-p",
),
gr.Slider(
minimum=10,
maximum=100,
value=30,
step=5,
label="Top-k",
),
],
)
if __name__ == "__main__":
demo.launch()