Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -51,9 +51,8 @@ def text2story(text):
|
|
51 |
generator = pipeline("text-generation", model="2173ars/llama-3-8b-Instruct-bnb-4bit-personal-shortstory")
|
52 |
|
53 |
# Create a prompt for the story
|
54 |
-
prompt = f"{text}"
|
55 |
|
56 |
-
# Generate the story - limit to a smaller max_length due to model size
|
57 |
story = generator(prompt,
|
58 |
min_length=100,
|
59 |
max_length=800,
|
@@ -78,7 +77,7 @@ def text2story(text):
|
|
78 |
except Exception as e:
|
79 |
# Fallback to simpler model if the advanced one fails
|
80 |
fallback_generator = pipeline('text-generation', model='gpt2')
|
81 |
-
fallback_prompt = f"
|
82 |
fallback_story = fallback_generator(fallback_prompt, min_length=100, num_return_sequences=1)[0]['generated_text']
|
83 |
return fallback_story.replace(fallback_prompt, "").strip()
|
84 |
|
@@ -155,18 +154,17 @@ progress_placeholder = st.empty()
|
|
155 |
|
156 |
# File uploader with Cantonese
|
157 |
with st.container():
|
158 |
-
st.subheader("請選擇一張畫作上載,格式必須係 JPG、JPEG 或 PNG! 最大 200 MB !")
|
159 |
-
uploaded_file = st.file_uploader(
|
160 |
-
"",
|
161 |
-
type=["jpg", "jpeg", "png"], # Limit file types
|
162 |
-
key="upload"
|
163 |
-
)
|
164 |
-
|
165 |
if uploaded_file is not None:
|
166 |
st.success("上載成功!")
|
167 |
else:
|
168 |
st.info("請選擇一張畫作上載,格式必須係 JPG、JPEG 或 PNG! 最大 200 MB !")
|
169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
if uploaded_file is not None:
|
171 |
# Save uploaded file
|
172 |
bytes_data = uploaded_file.getvalue()
|
|
|
51 |
generator = pipeline("text-generation", model="2173ars/llama-3-8b-Instruct-bnb-4bit-personal-shortstory")
|
52 |
|
53 |
# Create a prompt for the story
|
54 |
+
prompt = f" Story Context : {text} ; The story should have: - A clear beginning, middle, and end - Well-developed characters with motivation - A central theme or message - Engaging descriptions - Natural dialogue (if appropriate) - An emotional or thought-provoking conclusion "
|
55 |
|
|
|
56 |
story = generator(prompt,
|
57 |
min_length=100,
|
58 |
max_length=800,
|
|
|
77 |
except Exception as e:
|
78 |
# Fallback to simpler model if the advanced one fails
|
79 |
fallback_generator = pipeline('text-generation', model='gpt2')
|
80 |
+
fallback_prompt = f" Story Context : {text} ; The story should have: - A clear beginning, middle, and end - Well-developed characters with motivation - A central theme or message - Engaging descriptions - Natural dialogue (if appropriate) - An emotional or thought-provoking conclusion "
|
81 |
fallback_story = fallback_generator(fallback_prompt, min_length=100, num_return_sequences=1)[0]['generated_text']
|
82 |
return fallback_story.replace(fallback_prompt, "").strip()
|
83 |
|
|
|
154 |
|
155 |
# File uploader with Cantonese
|
156 |
with st.container():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
if uploaded_file is not None:
|
158 |
st.success("上載成功!")
|
159 |
else:
|
160 |
st.info("請選擇一張畫作上載,格式必須係 JPG、JPEG 或 PNG! 最大 200 MB !")
|
161 |
|
162 |
+
uploaded_file = st.file_uploader(
|
163 |
+
"",
|
164 |
+
type=["jpg", "jpeg", "png"], # Limit file types
|
165 |
+
key="upload"
|
166 |
+
)
|
167 |
+
|
168 |
if uploaded_file is not None:
|
169 |
# Save uploaded file
|
170 |
bytes_data = uploaded_file.getvalue()
|