Spaces:
Paused
Paused
File size: 1,219 Bytes
dbb7617 57fd8f5 dbb7617 9ecce17 dbb7617 9ecce17 dbb7617 |
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 |
import gradio as gr
import requests
import os
# Hugging Face API URL and token for the model
API_URL = "https://api-inference.huggingface.co/models/google/bigbird-pegasus-large-pubmed"
HUGGINGFACE_API_KEY = os.getenv("HUGGINGFACE_API_KEY")
# Define a function to send user input to the model
def get_bot_response(user_input):
headers = {"Authorization": f"Bearer {HUGGINGFACE_API_KEY}"}
response = requests.post(API_URL, headers=headers, json={"inputs": user_input})
# Debugging: print status and response
print("Status Code:", response.status_code)
print("Response:", response.text)
if response.status_code == 200:
result = response.json()
bot_response = result[0].get("generated_text", "Sorry, I couldn't generate a response.")
else:
bot_response = "Sorry, the model is currently unavailable."
return bot_response
# Set up Gradio interface
with gr.Blocks() as demo:
gr.Markdown("# Medical Consultation Chatbot")
user_input = gr.Textbox(label="Enter your question:")
output = gr.Textbox(label="Bot Response")
# On submit, call the get_bot_response function
user_input.submit(get_bot_response, user_input, output)
demo.launch()
|