Spaces:
Sleeping
Sleeping
Annaamalai
commited on
Commit
•
bdb2da1
1
Parent(s):
2983586
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the Hugging Face model for text generation
|
5 |
+
model = pipeline("text-generation")
|
6 |
+
|
7 |
+
# Streamlit app
|
8 |
+
def main():
|
9 |
+
st.title("Cherry Bot")
|
10 |
+
st.markdown("*Your Sweetest Companion*")
|
11 |
+
|
12 |
+
# Maintain a list to store text inputs for each chat
|
13 |
+
chat_inputs = []
|
14 |
+
|
15 |
+
# Add a sidebar to the app
|
16 |
+
with st.sidebar:
|
17 |
+
st.markdown("# Text Generation Settings")
|
18 |
+
# Slider for adjusting the maximum length of generated text
|
19 |
+
max_length = st.slider("Max Length of Generated Text:", min_value=10, max_value=200, value=50, step=10)
|
20 |
+
|
21 |
+
# Add a "New Chat" button
|
22 |
+
if st.button("New Chat"):
|
23 |
+
chat_inputs.append(st.text_area(f"Enter starting text for Chat {len(chat_inputs) + 1}:", height=100))
|
24 |
+
|
25 |
+
# Perform text generation for each chat
|
26 |
+
for idx, starting_text in enumerate(chat_inputs):
|
27 |
+
st.header(f"Chat {idx + 1}")
|
28 |
+
if st.button(f"Generate Text for Chat {idx + 1}"):
|
29 |
+
if starting_text:
|
30 |
+
# Generate text using the loaded model
|
31 |
+
generated_text = model(starting_text, max_length=max_length)[0]['generated_text']
|
32 |
+
|
33 |
+
# Display the generated text
|
34 |
+
st.write("Generated Text:")
|
35 |
+
st.write(generated_text)
|
36 |
+
|
37 |
+
if __name__ == "__main__":
|
38 |
+
main()
|