Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 3 |
+
|
| 4 |
+
model_id = "BioMistral/BioMistral-7B" # Of een clinical variant als je dat wilt
|
| 5 |
+
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(model_id)
|
| 8 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 9 |
+
|
| 10 |
+
def biomistral_chat(message, history):
|
| 11 |
+
prompt = f"### Question:\n{message}\n### Answer:\n"
|
| 12 |
+
response = pipe(prompt, max_new_tokens=256)[0]["generated_text"]
|
| 13 |
+
# Haal alleen het antwoorddeel eruit
|
| 14 |
+
answer = response.split("### Answer:")[-1].strip()
|
| 15 |
+
return answer
|
| 16 |
+
|
| 17 |
+
demo = gr.ChatInterface(biomistral_chat)
|
| 18 |
+
demo.launch()
|