| import gradio as gr |
| import requests |
|
|
| |
| API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2" |
| HEADERS = {"Authorization": "Bearer YOUR_HF_TOKEN"} |
|
|
| def chat_with_ai(prompt, history): |
| if not prompt.strip(): |
| return "", history |
| |
| |
| full_prompt = f"<s>[INST] You are a helpful AI project assistant. Answer clearly and concisely. {prompt} [/INST]" |
| |
| try: |
| response = requests.post(API_URL, headers=HEADERS, json={"inputs": full_prompt}) |
| result = response.json() |
| reply = result[0]["generated_text"].split("[/INST]")[-1].strip() |
| except Exception as e: |
| reply = f"⚠️ Error: {str(e)}. Please check your token or internet connection." |
| |
| history.append((prompt, reply)) |
| return "", history |
|
|
| |
| with gr.Blocks(theme="soft") as demo: |
| gr.Markdown("# 🤖 Hermus AI Project Assistant") |
| gr.Markdown("Ask me to write code, plan projects, or debug anything.") |
| |
| chatbot = gr.Chatbot(height=400) |
| msg = gr.Textbox(label="Your message", placeholder="Type your project question here...") |
| clear = gr.Button("Clear chat") |
| |
| msg.submit(chat_with_ai, [msg, chatbot], [msg, chatbot]) |
| clear.click(lambda: None, None, chatbot, queue=False) |
|
|
| demo.launch() |