Create app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,28 @@
|
|
| 1 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 2 |
import gradio as gr
|
| 3 |
-
import
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
|
| 5 |
+
API_URL = "http://localhost:8000/v1/chat/completions"
|
| 6 |
|
| 7 |
+
def chat_fn(message, history):
|
| 8 |
+
headers = {"Content-Type": "application/json"}
|
| 9 |
+
payload = {
|
| 10 |
+
"model": "MBZUAI/BiMediX2-8B-hf",
|
| 11 |
+
"messages": [{"role": "user", "content": message}],
|
| 12 |
+
"max_tokens": 512,
|
| 13 |
+
"temperature": 0.2
|
| 14 |
+
}
|
| 15 |
|
| 16 |
+
try:
|
| 17 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 18 |
+
data = response.json()
|
| 19 |
+
reply = data["choices"][0]["message"]["content"]
|
| 20 |
+
return reply
|
| 21 |
+
except Exception as e:
|
| 22 |
+
return f"Error: {str(e)}"
|
| 23 |
|
| 24 |
+
gr.ChatInterface(
|
| 25 |
+
fn=chat_fn,
|
| 26 |
+
title="BiMediX2 Medical Chatbot",
|
| 27 |
+
description="Ask any medical question."
|
| 28 |
+
).launch()
|