Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,17 @@
|
|
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 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
# Extract only the generated text from response
|
12 |
-
generated_text = result[0]["generated_text"]
|
13 |
-
|
14 |
-
# Remove the input prompt from the generated text
|
15 |
-
generated_text = generated_text[len(query):].strip() #strip() to remove leading spaces
|
16 |
-
|
17 |
-
return generated_text
|
18 |
-
|
19 |
-
# Create Gradio interface
|
20 |
iface = gr.Interface(
|
21 |
fn=medical_chatbot,
|
22 |
inputs=gr.Textbox(placeholder="Ask me a medical question..."),
|
|
|
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(query, max_length=200, num_return_sequences=1, temperature=0.7, top_k=50)
|
9 |
+
generated_text = result[0]["generated_text"][len(query):].strip()
|
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..."),
|