Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
|
|
|
| 4 |
bio_gpt = pipeline("text-generation", model="microsoft/biogpt")
|
| 5 |
|
| 6 |
def medical_chatbot(query):
|
| 7 |
try:
|
| 8 |
-
result = bio_gpt(
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
return generated_text
|
| 11 |
except Exception as e:
|
| 12 |
print(f"Error: {e}")
|
| 13 |
return "An error occurred."
|
| 14 |
|
|
|
|
| 15 |
iface = gr.Interface(
|
| 16 |
fn=medical_chatbot,
|
| 17 |
inputs=gr.Textbox(placeholder="Ask me a medical question..."),
|
|
@@ -19,4 +27,4 @@ iface = gr.Interface(
|
|
| 19 |
title="Medical Chatbot"
|
| 20 |
)
|
| 21 |
|
| 22 |
-
iface.launch(share=True)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load BioGPT model
|
| 5 |
bio_gpt = pipeline("text-generation", model="microsoft/biogpt")
|
| 6 |
|
| 7 |
def medical_chatbot(query):
|
| 8 |
try:
|
| 9 |
+
result = bio_gpt(
|
| 10 |
+
query,
|
| 11 |
+
max_length=10000, # Increased length for full response
|
| 12 |
+
num_return_sequences=5,
|
| 13 |
+
temperature=5.9, # Higher temperature for diverse responses
|
| 14 |
+
top_p=0.95 # Uses nucleus sampling instead of fixed top_k
|
| 15 |
+
)
|
| 16 |
+
generated_text = result[0]["generated_text"] # Full response without trimming
|
| 17 |
return generated_text
|
| 18 |
except Exception as e:
|
| 19 |
print(f"Error: {e}")
|
| 20 |
return "An error occurred."
|
| 21 |
|
| 22 |
+
# Create Gradio interface
|
| 23 |
iface = gr.Interface(
|
| 24 |
fn=medical_chatbot,
|
| 25 |
inputs=gr.Textbox(placeholder="Ask me a medical question..."),
|
|
|
|
| 27 |
title="Medical Chatbot"
|
| 28 |
)
|
| 29 |
|
| 30 |
+
iface.launch(share=True)
|