dhanvanth183 commited on
Commit
09abbfa
Β·
verified Β·
1 Parent(s): 1d8c363

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +109 -108
app.py CHANGED
@@ -1,108 +1,109 @@
1
- import streamlit as st
2
- import pandas as pd
3
- from openai_llms import LLMHandler
4
- import tempfile
5
- import os
6
-
7
- # Load environment variables for OpenAI API Key
8
- from dotenv import load_dotenv
9
-
10
- load_dotenv()
11
-
12
- # Initialize LLMHandler
13
- llm_handler = LLMHandler()
14
-
15
-
16
- def process_csv(file, user_prompt):
17
- """Read CSV, generate responses using LLMHandler, and return processed DataFrame."""
18
- df = pd.read_csv(file)
19
- responses = []
20
-
21
- for _, row in df.iterrows():
22
- try:
23
- response = llm_handler.generate_response(user_prompt, row.to_dict())
24
- responses.append(response)
25
- except Exception as e:
26
- responses.append(f"Error: {e}")
27
-
28
- df["Generated Text"] = responses
29
- return df
30
-
31
-
32
- # Streamlit UI
33
- st.set_page_config(page_title="Invitation Generator", page_icon="πŸ“œ", layout="wide")
34
-
35
- # Header
36
- st.title("Invite AI")
37
- st.markdown(
38
- """
39
- Welcome to the Invitation Generator! This tool helps you create personalized invitations using the power of AI.
40
- Follow the steps below to upload your data and generate professional invitation texts.
41
- """
42
- )
43
-
44
- # Section: Template Download and Instructions
45
- st.sidebar.title("Instructions")
46
- st.sidebar.markdown(
47
- """
48
- ### Template Download
49
- [Click here to download the suggested CSV template](http://surl.li/ptvzzv) πŸ“₯
50
-
51
- ### Required Fields
52
- - **Unique Identifier for each receiver**
53
- - **Name of the receiver**
54
- - **Designation/Job title of the receiver**
55
- - **Company/Organisation where the receiver works**
56
- - **Areas the receiver is interested in / has expertise in**
57
- - **Categorize receivers into groups** for consistent instructions.
58
- """
59
- )
60
-
61
- # Main Section
62
- st.markdown(
63
- """
64
- ### Steps to Use
65
- 1. **Download the template** from the sidebar.
66
- 2. **Fill out the details** as per the instructions.
67
- 3. **Upload the completed CSV file** below.
68
- 4. Enter a **prompt** to generate personalized invitations.
69
- """
70
- )
71
-
72
- # File uploader for CSV
73
- uploaded_file = st.file_uploader("πŸ“‚ Upload CSV File", type=["csv"])
74
- user_prompt = st.text_area(
75
- "✍️ Enter the prompt for generating invitation texts:",
76
- "Write professional invitation text tailored for the group.",
77
- height=150,
78
- )
79
-
80
- # Processing and displaying results
81
- if uploaded_file is not None and user_prompt:
82
- st.write("⏳ Processing your file... Please wait.")
83
- processed_df = process_csv(uploaded_file, user_prompt)
84
-
85
- # Display results
86
- st.write("### Generated Invitations")
87
- st.dataframe(processed_df, use_container_width=True)
88
-
89
- # Option to download the processed CSV
90
- with tempfile.NamedTemporaryFile(delete=False, suffix=".csv") as temp_file:
91
- processed_df.to_csv(temp_file.name, index=False)
92
- temp_file.close() # Ensure the file is properly closed before proceeding
93
-
94
- st.download_button(
95
- label="πŸ“₯ Download Results CSV",
96
- data=open(temp_file.name, "rb"),
97
- file_name="generated_invitations.csv",
98
- mime="text/csv",
99
- )
100
-
101
- # Safely delete the temporary file
102
- os.unlink(temp_file.name)
103
-
104
- # Footer
105
- st.markdown("---")
106
- st.markdown(
107
- "πŸ’‘ **Tip:** Ensure your data aligns with the provided template for accurate results."
108
- )
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ #from openai_llms import LLMHandler
4
+ from Groq_llms import LLMHandler
5
+ import tempfile
6
+ import os
7
+
8
+ # Load environment variables for OpenAI API Key
9
+ from dotenv import load_dotenv
10
+
11
+ load_dotenv()
12
+
13
+ # Initialize LLMHandler
14
+ llm_handler = LLMHandler()
15
+
16
+
17
+ def process_csv(file, user_prompt):
18
+ """Read CSV, generate responses using LLMHandler, and return processed DataFrame."""
19
+ df = pd.read_csv(file)
20
+ responses = []
21
+
22
+ for _, row in df.iterrows():
23
+ try:
24
+ response = llm_handler.generate_response(user_prompt, row.to_dict())
25
+ responses.append(response)
26
+ except Exception as e:
27
+ responses.append(f"Error: {e}")
28
+
29
+ df["Generated Text"] = responses
30
+ return df
31
+
32
+
33
+ # Streamlit UI
34
+ st.set_page_config(page_title="Invitation Generator", page_icon="πŸ’¬", layout="wide")
35
+
36
+ # Header
37
+ st.title("Invite AI")
38
+ st.markdown(
39
+ """
40
+ Welcome to the Invitation Generator! This tool helps you create personalized invitations using the power of AI.
41
+ Follow the steps below to upload your data and generate professional invitation texts.
42
+ """
43
+ )
44
+
45
+ # Section: Template Download and Instructions
46
+ st.sidebar.title("Instructions")
47
+ st.sidebar.markdown(
48
+ """
49
+ ### Template Download
50
+ [Click here to download the suggested CSV template](http://surl.li/ptvzzv) πŸ“₯
51
+
52
+ ### Required Fields
53
+ - **Unique Identifier for each receiver**
54
+ - **Name of the receiver**
55
+ - **Designation/Job title of the receiver**
56
+ - **Company/Organisation where the receiver works**
57
+ - **Areas the receiver is interested in / has expertise in**
58
+ - **Categorize receivers into groups** for consistent instructions.
59
+ """
60
+ )
61
+
62
+ # Main Section
63
+ st.markdown(
64
+ """
65
+ ### Steps to Use
66
+ 1. **Download the template** from the sidebar.
67
+ 2. **Fill out the details** as per the instructions.
68
+ 3. **Upload the completed CSV file** below.
69
+ 4. Enter a **prompt** to generate personalized invitations.
70
+ """
71
+ )
72
+
73
+ # File uploader for CSV
74
+ uploaded_file = st.file_uploader("πŸ“‚ Upload CSV File", type=["csv"])
75
+ user_prompt = st.text_area(
76
+ "✍️ Enter the prompt for generating invitation texts:",
77
+ "Write professional invitation text tailored for the group.",
78
+ height=150,
79
+ )
80
+
81
+ # Processing and displaying results
82
+ if uploaded_file is not None and user_prompt:
83
+ st.write("⏳ Processing your file... Please wait.")
84
+ processed_df = process_csv(uploaded_file, user_prompt)
85
+
86
+ # Display results
87
+ st.write("### Generated Invitations")
88
+ st.dataframe(processed_df, use_container_width=True)
89
+
90
+ # Option to download the processed CSV
91
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".csv") as temp_file:
92
+ processed_df.to_csv(temp_file.name, index=False)
93
+ temp_file.close() # Ensure the file is properly closed before proceeding
94
+
95
+ st.download_button(
96
+ label="πŸ“₯ Download Results CSV",
97
+ data=open(temp_file.name, "rb"),
98
+ file_name="generated_invitations.csv",
99
+ mime="text/csv",
100
+ )
101
+
102
+ # Safely delete the temporary file
103
+ os.unlink(temp_file.name)
104
+
105
+ # Footer
106
+ st.markdown("---")
107
+ st.markdown(
108
+ "πŸ’‘ **Tip:** Ensure your data aligns with the provided template for accurate results."
109
+ )