c
File size: 745 Bytes
e299696
6b5d4b4
 
e299696
6b5d4b4
e299696
6b5d4b4
 
 
 
 
 
 
 
e299696
6b5d4b4
 
 
 
 
 
 
e299696
6b5d4b4
 
 
 
 
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
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()