Delete app.py
Browse files
app.py
DELETED
@@ -1,61 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
from transformers import pipeline
|
3 |
-
from huggingface_hub import cached_download
|
4 |
-
import torch
|
5 |
-
from PIL import Image
|
6 |
-
|
7 |
-
# Pre-trained models
|
8 |
-
text_generator = pipeline("text-generation", model="gpt2")
|
9 |
-
question_answering = pipeline("question-answering", model="distilbert-base-cased-squad2")
|
10 |
-
image_generator = pipeline("image-generation", model="sd-v1-diffusion")
|
11 |
-
|
12 |
-
# Download models if not already present
|
13 |
-
models = ["gpt2", "distilbert-base-cased-squad2", "sd-v1-diffusion"]
|
14 |
-
for model in models:
|
15 |
-
cached_download(repo_id=f"huggingface/transformers/{model}", force_download=True)
|
16 |
-
|
17 |
-
# Story prompt input
|
18 |
-
prompt = st.text_input("Start your story with...", value="Once upon a time...")
|
19 |
-
|
20 |
-
# Generate story
|
21 |
-
generated_text = text_generator(prompt, max_length=1024)[0]["generated_text"]
|
22 |
-
|
23 |
-
# Text-to-speech and Text-to-text buttons
|
24 |
-
st.button("Speak the story", on_click=lambda: speak(generated_text))
|
25 |
-
generated_text_2 = st.button("Generate different story", on_click=lambda: generate_text(prompt))
|
26 |
-
|
27 |
-
# Generate question from story
|
28 |
-
question = st.text_input("Ask a question about the story...")
|
29 |
-
answer = question_answering(question=question, context=generated_text)["answer"]
|
30 |
-
|
31 |
-
# Generate image
|
32 |
-
image = image_generator(prompt="Image related to the story:")
|
33 |
-
image = Image.open(torch.ByteStorage.from_buffer(image[0]["image"]).read())
|
34 |
-
|
35 |
-
# Streamlit layout
|
36 |
-
st.title("Your Story")
|
37 |
-
st.write(generated_text)
|
38 |
-
st.image(image)
|
39 |
-
|
40 |
-
# Question and answer section
|
41 |
-
st.subheader("Ask and Learn")
|
42 |
-
st.write(f"Question: {question}")
|
43 |
-
st.write(f"Answer: {answer}")
|
44 |
-
|
45 |
-
# Text-to-text functionality
|
46 |
-
if generated_text_2:
|
47 |
-
generated_text_2 = text_generator(prompt, max_length=1024)[0]["generated_text"]
|
48 |
-
st.write("**New Story:**")
|
49 |
-
st.write(generated_text_2)
|
50 |
-
|
51 |
-
# Text-to-speech functionality
|
52 |
-
def speak(text):
|
53 |
-
# Your preferred text-to-speech implementation
|
54 |
-
# (e.g., ResponsiveVoice, gTTS) goes here
|
55 |
-
pass
|
56 |
-
|
57 |
-
st.write("* This app is still under development and may not always generate accurate or coherent results.")
|
58 |
-
st.write("* Please be mindful of the content generated by the AI models.")
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|