Spaces:
Runtime error
Runtime error
Update app.py
Browse files1234561 unmodified line89101112131415161718192021222324252627282 unmodified lines31323334353637383940412 unmodified lines4445464748495051from huggingface_hub import InferenceClientimport gradio as grimport os# Klient für die Inferenzclient = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")1 unmodified line# Geheime Eingabeaufforderung aus Umgebungsvariablensecret_prompt = os.getenv("SECRET_PROMPT")def format_prompt(new_message, history):prompt = secret_promptfor user_msg, bot_msg in history:prompt += f"[INST] {user_msg} [/INST]"prompt += f" {bot_msg}</s> "prompt += f"[INST] {new_message} [/INST]"return promptdef generate(prompt, history, temperature=0.25, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0):# Konfiguration der Parametertemperature = float(temperature)if temperature < 1e-2:temperature = 1e-2top_p = float(top_p)generate_kwargs = dict(temperature=temperature,max_new_tokens=max_new_tokens,2 unmodified linesdo_sample=True,seed=727,)formatted_prompt = format_prompt(prompt, history)stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)output = ""for response in stream:output += response.token.textyield output2 unmodified lines# Chatbot ohne Avatare und mit transparentem Designsamir_chatbot = gr.Chatbot(bubble_full_width=True, show_label=False, show_copy_button=False, likeable=False)# Minimalistisches Theme und Konfiguration der Gradio-Demotheme = 'syddharth/gray-minimal'demo = gr.ChatInterface(fn=generate, chatbot=samir_chatbot, title="Tutorial Master", theme=theme)demo.queue().launch(show_api=False)1234567891011121314151 unmodified line17181920212223242526272829303132333435362 unmodified lines3940414243444546472 unmodified lines50515253545556575859606162636465666768697071727374import jsonfrom huggingface_hub import InferenceClientimport gradio as grimport os# Laden der Prompts aus der JSON-Dateidef load_prompts_from_json(file_path):with open(file_path, 'r') as file:return json.load(file)# Angenommen, Sie haben eine JSON-Datei namens 'prompts.json'prompts = load_prompts_from_json('prompts.json')# Klient für die Inferenzclient = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")1 unmodified line# Geheime Eingabeaufforderung aus Umgebungsvariablensecret_prompt = os.getenv("SECRET_PROMPT")def format_prompt(new_message, history, prompt_type='default'):prompt = prompts.get(prompt_type, secret_prompt)for user_msg, bot_msg in history:prompt += f"[INST] {user_msg} [/INST]"prompt += f" {bot_msg}</s> "prompt += f"[INST] {new_message} [/INST]"return promptdef generate(prompt, history, temperature=0.25, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0, prompt_type='default'):# Konfiguration der Parametertemperature = float(temperature)if temperature < 1e-2:temperature = 1e-2top_p = float(top_p)generate_kwargs = dict(temperature=temperature,max_new_tokens=max_new_tokens,2 unmodified linesdo_sample=True,seed=727,)formatted_prompt = format_prompt(prompt, history, prompt_type)stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)output = ""for response in stream:output += response.token.textyield output2 unmodified lines# Chatbot ohne Avatare und mit transparentem Designsamir_chatbot = gr.Chatbot(bubble_full_width=True, show_label=False, show_copy_button=False, likeable=False)# Dropdown für Prompt-Typenprompt_type_dropdown = gr.Dropdown(choices=list(prompts.keys()), label="Prompt-Typ", value='default')# Minimalistisches Theme und Konfiguration der Gradio-Demotheme = 'syddharth/gray-minimal'demo = gr.Interface(fn=generate,inputs=[gr.Textbox(lines=2, label="Eingabe"),"state",gr.Slider(0, 1, value=0.25, label="Temperature"),gr.Slider(1, 2048, value=512, step=1, label="Max Tokens"),gr.Slider(0, 1, value=0.95, label="Top P"),gr.Slider(1, 2, value=1.0, label="Repetition Penalty"),prompt_type_dropdown],outputs=[samir_chatbot],title="Tutorial Master",theme=theme)demo.queue().launch(show_api=False)
app.py+32-9