Erfan11 commited on
Commit
c02aa1c
1 Parent(s): cbe3ce3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -23
app.py CHANGED
@@ -1,29 +1,37 @@
1
  import streamlit as st
2
- from transformers import GPT2LMHeadModel, GPT2Tokenizer
 
 
 
3
 
4
- # Load pre-trained model and tokenizer
5
- model_name = "gpt2"
6
- tokenizer = GPT2Tokenizer.from_pretrained(model_name)
7
- model = GPT2LMHeadModel.from_pretrained(model_name)
8
 
9
- def generate_text(prompt, max_length=50):
10
- # Encode the input prompt
11
- inputs = tokenizer.encode(prompt, return_tensors="pt")
12
-
13
- # Generate text
14
- outputs = model.generate(inputs, max_length=max_length, num_return_sequences=1)
15
-
16
- # Decode the generated text
17
- text = tokenizer.decode(outputs[0], skip_special_tokens=True)
18
- return text
19
 
20
- # Streamlit app
21
- st.title("GPT-2 Text Generator")
 
 
 
 
 
 
 
 
 
 
22
 
23
- prompt = st.text_area("Input", "Once upon a time...")
24
- max_length = st.slider("Max Length", min_value=10, max_value=100, value=50)
 
25
 
26
- if st.button("Generate"):
27
- generated_text = generate_text(prompt, max_length)
28
- st.subheader("Generated Text")
29
- st.write(generated_text)
 
1
  import streamlit as st
2
+ from text_generation import generate_text
3
+ from image_generation import generate_image_from_text
4
+ from video_generation import generate_simple_video
5
+ from PIL import Image
6
 
7
+ # Main Streamlit app
8
+ st.title("Multifunction AI App")
 
 
9
 
10
+ # Ability Selection
11
+ option = st.sidebar.selectbox("Select Functionality", ("Text Generation", "Image Generation", "Video Generation"))
12
+
13
+ # Text Generation
14
+ if option == "Text Generation":
15
+ prompt = st.text_area("Input", "Type a prompt for text generation...")
16
+ max_length = st.slider("Max Length", min_value=10, max_value=100, value=50)
 
 
 
17
 
18
+ if st.button("Generate Text"):
19
+ generated_text = generate_text(prompt, max_length)
20
+ st.subheader("Generated Text")
21
+ st.write(generated_text)
22
+
23
+ # Image Generation
24
+ elif option == "Image Generation":
25
+ prompt = st.text_area("Input", "Type a prompt for image generation...")
26
+
27
+ if st.button("Generate Image"):
28
+ image = generate_image_from_text(prompt)
29
+ st.image(image, caption="Generated Image", use_column_width=True)
30
 
31
+ # Video Generation
32
+ elif option == "Video Generation":
33
+ prompt = st.text_area("Input", "Type a prompt for video generation...")
34
 
35
+ if st.button("Generate Video"):
36
+ video_path = generate_simple_video(prompt)
37
+ st.video(video_path)