Spaces:
Running
Running
File size: 1,252 Bytes
cf6d982 |
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 30 31 32 33 34 35 36 37 38 39 40 |
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
# β
Choose a public model that is available on Hugging Face
MODEL_NAME = "mistralai/Mistral-7B-Instruct" # Alternative: "microsoft/BioGPT-Large"
# β
Load the tokenizer and model
try:
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
except Exception as e:
print(f"Error loading model: {e}")
model = None # Prevents crashing if model doesn't load
def diagnose(symptoms):
if model is None:
return "β οΈ Error: AI model failed to load. Try again later."
prompt = f"I have the following symptoms: {symptoms}. What could it be?"
inputs = tokenizer(prompt, return_tensors="pt")
# β
Generate AI response
output = model.generate(**inputs, max_length=200)
response = tokenizer.decode(output[0], skip_special_tokens=True)
return response
# β
Create a simple web UI
interface = gr.Interface(
fn=diagnose,
inputs="text",
outputs="text",
title="AI Symptom Checker",
description="Enter your symptoms, and the AI will suggest possible conditions."
)
# β
Launch the web app
if __name__ == "__main__":
interface.launch()
|