Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
from groq import Groq
|
| 5 |
+
|
| 6 |
+
# Check if Groq API should be used
|
| 7 |
+
use_groq = False # Update this to True if you want to use Groq API
|
| 8 |
+
|
| 9 |
+
# Groq setup
|
| 10 |
+
if use_groq:
|
| 11 |
+
client = Groq(
|
| 12 |
+
api_key=os.environ.get("GROQ_API_KEY"),
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
# Hugging Face model setup using pipeline
|
| 16 |
+
pipe = pipeline("text-generation", model="RayyanAhmed9477/Health-Chatbot")
|
| 17 |
+
|
| 18 |
+
# Streamlit app setup
|
| 19 |
+
st.title("Healthcare Chatbot")
|
| 20 |
+
st.write("Ask me anything related to healthcare!")
|
| 21 |
+
|
| 22 |
+
user_input = st.text_input("Your Question:")
|
| 23 |
+
|
| 24 |
+
if user_input:
|
| 25 |
+
# If Groq API is to be used, modify this accordingly
|
| 26 |
+
if use_groq:
|
| 27 |
+
chat_completion = client.chat.completions.create(
|
| 28 |
+
messages=[
|
| 29 |
+
{"role": "user", "content": user_input}
|
| 30 |
+
],
|
| 31 |
+
model="RayyanAhmed9477/Health-Chatbot",
|
| 32 |
+
)
|
| 33 |
+
st.write(chat_completion.choices[0].message.content)
|
| 34 |
+
else:
|
| 35 |
+
# If Groq is not being used, directly use Hugging Face pipeline
|
| 36 |
+
messages = [{"role": "user", "content": user_input}]
|
| 37 |
+
response = pipe(messages)
|
| 38 |
+
st.write(response[0]["generated_text"])
|