Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,61 +1,61 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
|
3 |
-
|
4 |
-
# Load the fine-tuned model and tokenizer
|
5 |
-
@st.cache_resource # Cache model to avoid reloading
|
6 |
-
def load_model():
|
7 |
-
model_directory = "
|
8 |
-
model = AutoModelForCausalLM.from_pretrained(model_directory)
|
9 |
-
tokenizer = AutoTokenizer.from_pretrained(model_directory)
|
10 |
-
return model, tokenizer
|
11 |
-
|
12 |
-
# Load model and tokenizer
|
13 |
-
model, tokenizer = load_model()
|
14 |
-
|
15 |
-
# Create a pipeline
|
16 |
-
question_completion_pipeline = pipeline(
|
17 |
-
"text-generation",
|
18 |
-
model=model,
|
19 |
-
tokenizer=tokenizer,
|
20 |
-
device=-1
|
21 |
-
)
|
22 |
-
|
23 |
-
# Streamlit UI
|
24 |
-
st.title("Question Completion Model")
|
25 |
-
st.write("Provide a partial question, and the model will complete it.")
|
26 |
-
|
27 |
-
partial_question = st.text_input("Enter a partial question:", "")
|
28 |
-
|
29 |
-
if st.button("Complete Question"):
|
30 |
-
if partial_question.strip():
|
31 |
-
output = question_completion_pipeline(
|
32 |
-
partial_question,
|
33 |
-
max_length=60,
|
34 |
-
num_return_sequences=1,
|
35 |
-
do_sample=True
|
36 |
-
)
|
37 |
-
|
38 |
-
completed_question = output[0]["generated_text"]
|
39 |
-
st.success(f"Completed Question: {completed_question}")
|
40 |
-
|
41 |
-
else:
|
42 |
-
st.warning("Please enter a partial question.")
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
|
3 |
+
|
4 |
+
# Load the fine-tuned model and tokenizer
|
5 |
+
@st.cache_resource # Cache model to avoid reloading
|
6 |
+
def load_model():
|
7 |
+
model_directory = "Vaishu16/QC_fine_tuned_model"
|
8 |
+
model = AutoModelForCausalLM.from_pretrained(model_directory)
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_directory)
|
10 |
+
return model, tokenizer
|
11 |
+
|
12 |
+
# Load model and tokenizer
|
13 |
+
model, tokenizer = load_model()
|
14 |
+
|
15 |
+
# Create a pipeline
|
16 |
+
question_completion_pipeline = pipeline(
|
17 |
+
"text-generation",
|
18 |
+
model=model,
|
19 |
+
tokenizer=tokenizer,
|
20 |
+
device=-1
|
21 |
+
)
|
22 |
+
|
23 |
+
# Streamlit UI
|
24 |
+
st.title("Question Completion Model")
|
25 |
+
st.write("Provide a partial question, and the model will complete it.")
|
26 |
+
|
27 |
+
partial_question = st.text_input("Enter a partial question:", "")
|
28 |
+
|
29 |
+
if st.button("Complete Question"):
|
30 |
+
if partial_question.strip():
|
31 |
+
output = question_completion_pipeline(
|
32 |
+
partial_question,
|
33 |
+
max_length=60,
|
34 |
+
num_return_sequences=1,
|
35 |
+
do_sample=True
|
36 |
+
)
|
37 |
+
|
38 |
+
completed_question = output[0]["generated_text"]
|
39 |
+
st.success(f"Completed Question: {completed_question}")
|
40 |
+
|
41 |
+
else:
|
42 |
+
st.warning("Please enter a partial question.")
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
|
50 |
+
|
51 |
+
|
52 |
+
|
53 |
+
|
54 |
+
|
55 |
+
|
56 |
+
|
57 |
+
|
58 |
+
|
59 |
+
|
60 |
+
|
61 |
+
|