Dua Rajper commited on
Commit
4dbe18e
·
verified ·
1 Parent(s): f70420d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -23
app.py CHANGED
@@ -1,30 +1,42 @@
1
  import streamlit as st
2
- import os
3
- from google import genai
4
- from google.genai import types
5
- from kaggle_secrets import UserSecretsClient
6
 
 
 
 
7
 
8
- # Get API key from environment variables
9
- GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
 
 
 
10
 
11
- # Initialize GenAI client
12
- client = genai.Client(api_key=GOOGLE_API_KEY)
13
 
14
- # Define functions for different functionalities
15
- # ... (Include your code snippets here, refactoring as needed) ...
 
 
 
 
 
 
 
 
16
 
17
- # Example function from your code
18
- def generate_text(prompt):
19
- response = client.models.generate_content(
20
- model="gemini-2.0-flash",
21
- contents=prompt
22
- )
23
- return response.text
24
 
25
- # Streamlit interface
26
- st.title("My GenAI App")
27
- user_input = st.text_input("Enter your prompt:")
28
- if user_input:
29
- output = generate_text(user_input)
30
- st.write(output)
 
 
 
 
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'])