Dua Rajper commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,42 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 3 |
-
from google import genai
|
| 4 |
-
from google.genai import types
|
| 5 |
-
from kaggle_secrets import UserSecretsClient
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
)
|
| 23 |
-
return response.text
|
| 24 |
|
| 25 |
-
|
| 26 |
-
st.
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# Set up Streamlit UI
|
| 5 |
+
st.set_page_config(page_title="Text Prompting Demo", layout="centered")
|
| 6 |
+
st.title("🤖 Text Prompting using Transformers")
|
| 7 |
|
| 8 |
+
# Add model selector
|
| 9 |
+
task_option = st.selectbox(
|
| 10 |
+
"Select Task",
|
| 11 |
+
("Text Generation", "Text Classification", "Question Answering")
|
| 12 |
+
)
|
| 13 |
|
| 14 |
+
# User input
|
| 15 |
+
user_input = st.text_area("Enter your input text", height=150)
|
| 16 |
|
| 17 |
+
# Run pipeline based on task
|
| 18 |
+
if st.button("Generate Output"):
|
| 19 |
+
if not user_input.strip():
|
| 20 |
+
st.warning("Please enter some text input.")
|
| 21 |
+
else:
|
| 22 |
+
if task_option == "Text Generation":
|
| 23 |
+
generator = pipeline("text-generation", model="gpt2")
|
| 24 |
+
output = generator(user_input, max_length=50, num_return_sequences=1)
|
| 25 |
+
st.subheader("Generated Text")
|
| 26 |
+
st.write(output[0]['generated_text'])
|
| 27 |
|
| 28 |
+
elif task_option == "Text Classification":
|
| 29 |
+
classifier = pipeline("sentiment-analysis")
|
| 30 |
+
output = classifier(user_input)
|
| 31 |
+
st.subheader("Classification Result")
|
| 32 |
+
st.json(output)
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
elif task_option == "Question Answering":
|
| 35 |
+
context = st.text_area("Enter context for question answering", height=150)
|
| 36 |
+
if not context.strip():
|
| 37 |
+
st.warning("Please provide context.")
|
| 38 |
+
else:
|
| 39 |
+
qa = pipeline("question-answering")
|
| 40 |
+
result = qa(question=user_input, context=context)
|
| 41 |
+
st.subheader("Answer")
|
| 42 |
+
st.write(result['answer'])
|