Belva1 commited on
Commit
dbb7617
1 Parent(s): 5531b3a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import os
4
+
5
+ # Hugging Face API URL and token for the model
6
+ API_URL = "https://api-inference.huggingface.co/models/ContactDoctor/Bio-Medical-MultiModal-Llama-3-8B-V1"
7
+ HUGGINGFACE_API_KEY = os.getenv("HUGGINGFACE_API_KEY")
8
+
9
+ # Define a function to send user input to the model
10
+ def get_bot_response(user_input):
11
+ headers = {"Authorization": f"Bearer {HUGGINGFACE_API_KEY}"}
12
+ response = requests.post(API_URL, headers=headers, json={"inputs": user_input})
13
+ if response.status_code == 200:
14
+ result = response.json()
15
+ bot_response = result[0]["generated_text"]
16
+ else:
17
+ bot_response = "Sorry, the model is currently unavailable."
18
+ return bot_response
19
+
20
+ # Set up Gradio interface
21
+ with gr.Blocks() as demo:
22
+ gr.Markdown("# Medical Consultation Chatbot")
23
+ user_input = gr.Textbox(label="Enter your question:")
24
+ output = gr.Textbox(label="Bot Response")
25
+
26
+ # On submit, call the get_bot_response function
27
+ user_input.submit(get_bot_response, user_input, output)
28
+
29
+ demo.launch()