Ghmustafa11 commited on
Commit
782f6be
·
verified ·
1 Parent(s): e2e8dd5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -107
app.py CHANGED
@@ -1,90 +1,15 @@
1
  import streamlit as st
2
  from fpdf import FPDF
3
- import os
4
 
5
- # Function to create various types of documents
6
- def generate_document(doc_type, text, style="formal"):
7
- if doc_type == "Proposal":
8
- if style == "formal":
9
- return f"Dear Sir/Madam,\n\nI am writing to propose the following idea:\n\n{text}\n\nSincerely,\nYour Name"
10
- elif style == "casual":
11
- return f"Hey there!\n\nI’ve been thinking about this idea:\n\n{text}\n\nLet me know what you think!\nCheers!"
12
- elif style == "business":
13
- return f"Subject: Proposal for the Idea\n\nDear [Recipient's Name],\n\nI would like to formally propose the following idea:\n\n{text}\n\nLooking forward to your feedback.\nBest regards,\n[Your Name]"
14
- else:
15
- return f"Proposal Idea:\n\n{text}\n\nBest regards,\n[Your Name]"
16
-
17
- elif doc_type == "Letter":
18
- return f"Dear [Recipient's Name],\n\n{text}\n\nSincerely,\n[Your Name]"
19
-
20
- elif doc_type == "Report":
21
- return f"Report: {text}"
22
-
23
- elif doc_type == "Message":
24
- return f"Message:\n\n{text}"
25
-
26
- elif doc_type == "Notice":
27
- return f"NOTICE:\n\n{text}"
28
-
29
- else:
30
- return f"Document:\n\n{text}"
31
-
32
- def chatbot_response(user_input):
33
- user_input = user_input.lower() # Normalize the input to lowercase
34
-
35
- # Friendly and conversational responses
36
- if "hello" in user_input or "hi" in user_input:
37
- return "Hey there! 😊 How’s everything going? How can I assist you today?"
38
-
39
- elif "how are you" in user_input:
40
- return "I’m doing great, thanks for asking! How about you? 😊"
41
-
42
- elif "proposal" in user_input:
43
- return ("I’d be happy to help with your proposal! 🎯 Would you like help with the structure, "
44
- "content, or brainstorming ideas for your proposal? Let me know what you need, and I’ll guide you through it!")
45
-
46
- elif "letter" in user_input:
47
- return ("I can help you with writing a letter! 💌 What type of letter are you writing? "
48
- "Is it formal, informal, or something else? Let me know, and I'll assist you in crafting the perfect letter!")
49
-
50
- elif "report" in user_input:
51
- return ("Reports can be tricky! 📊 Let me know what type of report you're working on (business, research, etc.), "
52
- "and I can help with structure, content, or formatting.")
53
-
54
- elif "help" in user_input:
55
- return ("Of course! 😊 I’m here for you. What do you need help with today? Writing, editing, or something else?")
56
-
57
- elif "thank you" in user_input:
58
- return "You're very welcome! 😊 Always happy to help!"
59
-
60
- elif "goodbye" in user_input or "bye" in user_input:
61
- return "Goodbye for now! 👋 Don’t hesitate to reach out again whenever you need assistance!"
62
-
63
- elif "how do i" in user_input or "what is" in user_input:
64
- return "Great question! Let me guide you through it. What do you need help with? I'll make it easy for you to understand!"
65
-
66
- else:
67
- return ("Hmm, I didn’t quite catch that, but I’m all ears! 😊 Tell me a bit more, "
68
- "and I’ll do my best to help. Whether it’s a proposal, letter, report, or something else, "
69
- "I’m here to assist with anything you need!")
70
-
71
-
72
- # Function to generate and return the PDF of the document
73
  def generate_pdf(document_text):
74
  pdf = FPDF()
75
  pdf.add_page()
76
-
77
- # Check if DejaVu font exists, if not fallback to default
78
- font_path = 'DejaVuSans.ttf'
79
- if os.path.exists(font_path):
80
- pdf.add_font('DejaVu', '', font_path, uni=True)
81
- pdf.set_font('DejaVu', '', 12)
82
- else:
83
- pdf.set_font('Arial', '', 12) # Fallback font
84
-
85
  # Title
86
- pdf.cell(200, 10, txt="Generated Document", ln=True, align="C")
87
-
88
  # Adding the document text
89
  pdf.ln(10) # Line break
90
  pdf.multi_cell(0, 10, document_text) # Allow wrapping text
@@ -93,43 +18,34 @@ def generate_pdf(document_text):
93
 
94
  # Streamlit app
95
  def main():
96
- st.title("GM: Document Generator with Chatbot")
97
-
98
- # Chatbot interaction
99
- st.subheader("Chat with me! I'm your friendly assistant. 😊")
100
- user_input = st.text_input("Ask me anything:", "")
101
-
102
- if user_input:
103
- response = chatbot_response(user_input)
104
- st.write(f"**Bot**: {response}")
105
-
106
- # Document input and generation
107
- st.subheader("Generate Your Document")
108
-
109
- doc_type = st.selectbox("What kind of document do you want to create?", ["Proposal", "Letter", "Report", "Message", "Notice"])
110
 
111
- document_text = st.text_area(f"Write your {doc_type} here...", height=150)
 
112
 
113
- style = st.selectbox("Choose a writing style:", ["formal", "casual", "business"])
 
114
 
115
- if st.button("Generate Document"):
116
- if document_text:
117
- document = generate_document(doc_type, document_text, style)
118
- st.subheader(f"Generated {doc_type}:")
119
- st.markdown(f"```\n{document}\n```")
 
120
 
121
- # PDF Download Button
122
- pdf = generate_pdf(document)
123
- pdf_output = pdf.output(dest='S') # No encoding issues
124
 
 
125
  st.download_button(
126
- label="Download PDF",
127
  data=pdf_output,
128
- file_name=f"{doc_type.lower()}.pdf",
129
  mime="application/pdf"
130
  )
131
  else:
132
- st.warning("Please write your document text.")
133
 
134
  if __name__ == "__main__":
135
  main()
 
1
  import streamlit as st
2
  from fpdf import FPDF
 
3
 
4
+ # Function to create a PDF document
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  def generate_pdf(document_text):
6
  pdf = FPDF()
7
  pdf.add_page()
8
+ pdf.set_font("Arial", size=12)
9
+
 
 
 
 
 
 
 
10
  # Title
11
+ pdf.cell(200, 10, txt="Generated Proposal", ln=True, align="C")
12
+
13
  # Adding the document text
14
  pdf.ln(10) # Line break
15
  pdf.multi_cell(0, 10, document_text) # Allow wrapping text
 
18
 
19
  # Streamlit app
20
  def main():
21
+ st.title("Proposal Generator App")
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
+ # Instructions for the user
24
+ st.subheader("Write your proposal below")
25
 
26
+ # Input text for the proposal
27
+ proposal_text = st.text_area("Enter the content of your proposal:", height=300)
28
 
29
+ # Check if the text is provided and if the button is clicked
30
+ if st.button("Generate Proposal"):
31
+ if proposal_text:
32
+ # Display the written proposal
33
+ st.subheader("Your Proposal:")
34
+ st.markdown(f"```\n{proposal_text}\n```")
35
 
36
+ # Generate the PDF
37
+ pdf = generate_pdf(proposal_text)
38
+ pdf_output = pdf.output(dest='S').encode('latin1') # Convert PDF to bytes for download
39
 
40
+ # Download button for the generated PDF
41
  st.download_button(
42
+ label="Download Proposal as PDF",
43
  data=pdf_output,
44
+ file_name="proposal.pdf",
45
  mime="application/pdf"
46
  )
47
  else:
48
+ st.warning("Please enter the content of your proposal.")
49
 
50
  if __name__ == "__main__":
51
  main()