amaltese commited on
Commit
56f8448
·
verified ·
1 Parent(s): 8b79af3

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import torch
4
+
5
+ # Load Phi-2 model and tokenizer
6
+ MODEL_NAME = "microsoft/phi-2"
7
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
8
+ model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
9
+
10
+ def get_response(user_input):
11
+ input_ids = tokenizer(user_input, return_tensors="pt").input_ids
12
+ with torch.no_grad():
13
+ output = model.generate(input_ids, max_length=200)
14
+ response = tokenizer.decode(output[:, input_ids.shape[-1]:][0], skip_special_tokens=True)
15
+ return response
16
+
17
+ # Streamlit UI
18
+ st.title("Study Buddy Chatbot 📚")
19
+ st.write("Ask a question or type a topic, and I'll help you learn!")
20
+
21
+ user_input = st.text_input("Type your question or topic:")
22
+ if user_input:
23
+ response = get_response(user_input)
24
+ st.write("🤖 Chatbot:", response)