abuzarAli commited on
Commit
7bcdd52
·
verified ·
1 Parent(s): bd08d96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -20
app.py CHANGED
@@ -1,29 +1,41 @@
1
  import os
2
  import streamlit as st
3
- from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
4
- import torch
5
- #
6
- # Use the pipeline method
7
- pipe = pipeline("text-generation", model="RayyanAhmed9477/Health-Chatbot")
8
 
9
- # Load the model directly
10
- model_name = "RayyanAhmed9477/Health-Chatbot"
11
- tokenizer = AutoTokenizer.from_pretrained(model_name)
12
- model = AutoModelForCausalLM.from_pretrained(model_name)
13
 
14
- # Streamlit app setup
15
- st.title("Healthcare Chatbot")
16
- st.write("Ask me anything related to healthcare!")
 
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  user_input = st.text_input("Your Question:")
19
 
20
  if user_input:
21
- # Using the pipeline method
22
- response = pipe([{"role": "user", "content": user_input}])
23
- st.write(f"Response (using pipeline): {response[0]['generated_text']}")
 
 
 
24
 
25
- # Using the model directly
26
- inputs = tokenizer(user_input, return_tensors="pt")
27
- outputs = model.generate(inputs["input_ids"], max_length=100, num_return_sequences=1)
28
- generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
29
- st.write(f"Response (using direct model load): {generated_text}")
 
1
  import os
2
  import streamlit as st
3
+ from groq import Groq
 
 
 
 
4
 
5
+ # Set your API key in the environment
6
+ os.environ["GROQ_API_KEY"] = "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"
 
 
7
 
8
+ # Initialize Groq client with the API key from the environment
9
+ client = Groq(
10
+ api_key=os.environ.get("GROQ_API_KEY"),
11
+ )
12
 
13
+ # Function to interact with Groq API and get responses
14
+ def get_chat_response(user_message):
15
+ chat_completion = client.chat.completions.create(
16
+ messages=[
17
+ {
18
+ "role": "user",
19
+ "content": user_message,
20
+ }
21
+ ],
22
+ model="llama-3.3-70b-versatile",
23
+ )
24
+ return chat_completion.choices[0].message.content
25
+
26
+ # Streamlit UI setup
27
+ st.title("AI-based Healthcare Chatbot")
28
+ st.write("Welcome to the Healthcare Chatbot! Ask me anything about health.")
29
+
30
+ # Text input for user query
31
  user_input = st.text_input("Your Question:")
32
 
33
  if user_input:
34
+ # Get the response from Groq API
35
+ response = get_chat_response(user_input)
36
+
37
+ # Display the chatbot's response
38
+ st.write("Chatbot Response:")
39
+ st.write(response)
40
 
41
+ # You can add more user-friendly features like history or options to rephrase responses, etc.