CoolFace
Apppublic

otzdarva/friendly_assistant

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py65 linesDownload Raw Back to root
1import os2import re3import gradio as gr4import edge_tts5import asyncio6import time7import tempfile8from huggingface_hub import InferenceClient9 10client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")11 12system_instructions = """[INST] Custom Instruction:13 14As a friendly assistant, I will respond to your questions in English, explaining things in a way that a 10-year-old can understand.15 16I will aim to be:17Clear: Use simple language and short sentences18Concise: Get straight to the point and avoid jargon19Friendly: Be kind, patient, and understanding20Fun: Add a dash of humor and personality to my responses21 22I'll explain things in a way that's easy to understand, using examples and analogies to help you grasp the concept. I'll be your guide, your mentor, and your friend.23 24So, go ahead and ask me anything! I'm here to help you learn and grow.25 26Note: Limit the answer to 200 words at most!27"""28 29async def generate(prompt):30    generate_kwargs = dict(31        temperature=0.6,32        max_new_tokens=256,33        top_p=0.95,34        repetition_penalty=1,35        do_sample=True,36        seed=42,37    )38    formatted_prompt = system_instructions + prompt + "[/INST]"39    stream = client.text_generation(40        formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)41    output = ""42    for response in stream:43        output += response.token.text44 45    return output46 47# Gradio userinterface...48interface = gr.Interface(49    fn=generate,50    inputs=gr.Textbox(lines=3, placeholder="Ask me anything..."),51    outputs="text",52    title="Friendly Assistant ๐Ÿ‘€",53    description="Ask me anything, and I'll explain it in a way that's easy to understand!",54    #theme="huggingface",55    examples=[56        ["What is thermodynamics?"],57        ["what is string theory?"],58        ["Is time travel possible just like in movies?"]59    ]60)61 62 63# Launch the interface64if __name__ == "__main__":65    interface.launch()