| import gradio as gr |
| import requests |
| import json |
|
|
| API_URL = "http://localhost:8000/v1/chat/completions" |
|
|
| def chat_fn(message, history): |
| headers = {"Content-Type": "application/json"} |
| payload = { |
| "model": "MBZUAI/BiMediX2-8B-hf", |
| "messages": [{"role": "user", "content": message}], |
| "max_tokens": 512, |
| "temperature": 0.2 |
| } |
|
|
| try: |
| response = requests.post(API_URL, headers=headers, json=payload) |
| data = response.json() |
| reply = data["choices"][0]["message"]["content"] |
| return reply |
| except Exception as e: |
| return f"Error: {str(e)}" |
|
|
| gr.ChatInterface( |
| fn=chat_fn, |
| title="BiMediX2 Medical Chatbot", |
| description="Ask any medical question." |
| ).launch() |
|
|