File size: 1,042 Bytes
bded7d2 a3ea183 bded7d2 a3ea183 4c8b754 a3ea183 4c8b754 a3ea183 4c8b754 a3ea183 4c8b754 a3ea183 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import gradio as gr
from huggingface_hub import InferenceClient
client = InferenceClient("mistralai/Mistral-7B-v0.1")
# Fixed temperature value
fixed_temperature = 0.9 # You can adjust this value as needed
def generate(prompt, max_new_tokens=6056, top_p=0.95, repetition_penalty=1.0):
top_p = float(top_p)
generate_kwargs = dict(
temperature=fixed_temperature,
max_new_tokens=max_new_tokens,
top_p=top_p,
repetition_penalty=repetition_penalty,
do_sample=True,
seed=42,
)
formatted_prompt = f"<s>[INST] {prompt} [/INST]"
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
output = ""
for response in stream:
output += response.token.text
yield output
return output
iface = gr.Interface(
fn=generate,
inputs="text",
outputs="text",
title="Mistralai-Mistral-7B-Instruct Chat",
live=False # Set live to False to add a "Submit" button
)
iface.launch() |