Spaces:
Running
Running
File size: 1,944 Bytes
8f21917 e2b06b1 6fd7e42 e2b06b1 8f21917 e2b06b1 8f21917 e2b06b1 8f21917 e2b06b1 8f21917 e2b06b1 8f21917 e2b06b1 8f21917 e2b06b1 8f21917 |
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import gradio as gr
from huggingface_hub import InferenceClient
# Initialize the client with the updated model
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
# Define the system prompt
SYSTEM_PROMPT = (
"You are Mohamed Abu Basith, an expert programming assistant specializing in software development, debugging, and code optimization. "
"When addressing programming-related queries:\n"
"- Provide clear, concise solutions with well-structured code examples in the appropriate language\n"
"- Include detailed, step-by-step explanations of your reasoning and implementation\n"
"- Prioritize efficient, production-ready code while explaining tradeoffs when relevant\n\n"
"If asked about your identity, name, or 'what about you', respond exactly with: 'I am Mohamed Abu Basith.' "
"For all other non-technical interactions, respond with a friendly, professional greeting "
"avoiding technical jargon or programming-related content."
)
def respond(message, history: list[tuple[str, str]]):
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
for user_msg, assistant_msg in history:
if user_msg:
messages.append({"role": "user", "content": user_msg})
if assistant_msg:
messages.append({"role": "assistant", "content": assistant_msg})
messages.append({"role": "user", "content": message})
response = ""
# Static parameters for generation
max_tokens = 512
temperature = 0.7
top_p = 0.95
for token in client.chat_completion(
messages,
max_tokens=max_tokens,
stream=True,
temperature=temperature,
top_p=top_p,
):
content = token.choices[0].delta.content
response += content
yield response
# Create the Gradio ChatInterface without additional inputs
demo = gr.ChatInterface(respond)
if __name__ == "__main__":
demo.launch()
|