Sobit commited on
Commit
8c95cb1
·
verified ·
1 Parent(s): c87d44d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -16
app.py CHANGED
@@ -15,7 +15,7 @@ litellm.api_key = "AIzaSyAlNlvB2unkbmkL6zweKVkjYEOVqIgovw4"
15
  os.environ['SERPER_API_KEY'] = "d9295b6ec268aad1fa375484f1e3ce556329973d"
16
 
17
  # Define the LLM
18
- llm = "gemini/gemini-1.5-flash-exp-0827"
19
 
20
  # Initialize the tool for internet searching capabilities
21
  tool = SerperDevTool()
@@ -129,42 +129,55 @@ def process_cv(file):
129
 
130
 
131
 
132
-
133
  def save_html_to_file(html_content):
134
  output_file_path = "Portfolio_generated_by_FiftyBit.html"
135
  with open(output_file_path, "w") as f:
136
  f.write(html_content)
137
  return output_file_path
138
 
 
139
  def upload_file(filepath):
140
  name = Path(filepath).name
141
  html_content = process_cv(filepath) # Get HTML content from the CV
142
 
 
143
  clean_html_output = html_content.replace("```html", '').replace("```", '').strip()
144
- gr.Markdown("# Preview of Your Portfolio:")
145
- # Save the HTML content to a file
 
 
 
 
 
 
 
 
 
146
  file_path = save_html_to_file(clean_html_output)
147
-
148
- return clean_html_output, gr.UploadButton(visible=False), gr.DownloadButton(label=f"Download Code", value=file_path, visible=True)
149
 
150
  def download_file():
151
  return [gr.UploadButton(label=f"Regenerate", visible=True), gr.DownloadButton(visible=False)]
152
 
 
153
  with gr.Blocks() as demo:
154
- gr.Markdown("# CV-2-Portfolio Site Generator")
155
- gr.Markdown("Upload your CV in PDF or DOCX format for analysis and portfolio webpage generation.")
156
-
157
-
158
  u = gr.UploadButton("Upload CV (.pdf or .docx)", file_count="single")
159
  d = gr.DownloadButton("Download Portfolio", visible=False)
160
-
161
- output_preview = gr.HTML(label="Webpage Preview" , value="<style>iframe { width: 100%; height: 600px; }</style><iframe srcdoc='Portfolio_generated_by_FiftyBit.html'></iframe>" ) # HTML output for preview
162
 
163
-
 
164
 
165
- # Connect the upload button to the upload_file function
166
  u.upload(upload_file, u, [output_preview, u, d])
167
-
168
  # Handle download button click
169
  d.click(download_file, None, [u, d])
170
- demo.launch(debug=True)
 
 
 
 
 
15
  os.environ['SERPER_API_KEY'] = "d9295b6ec268aad1fa375484f1e3ce556329973d"
16
 
17
  # Define the LLM
18
+ llm = "gemini/gemini-1.5-flash-exp-0827" # Your LLM model
19
 
20
  # Initialize the tool for internet searching capabilities
21
  tool = SerperDevTool()
 
129
 
130
 
131
 
 
132
  def save_html_to_file(html_content):
133
  output_file_path = "Portfolio_generated_by_FiftyBit.html"
134
  with open(output_file_path, "w") as f:
135
  f.write(html_content)
136
  return output_file_path
137
 
138
+
139
  def upload_file(filepath):
140
  name = Path(filepath).name
141
  html_content = process_cv(filepath) # Get HTML content from the CV
142
 
143
+ # Clean the HTML content (but keep this simple to start with)
144
  clean_html_output = html_content.replace("```html", '').replace("```", '').strip()
145
+
146
+ # Debugging print to check the HTML content
147
+ print("HTML content:", clean_html_output)
148
+
149
+ # Prepare an iframe to embed the HTML content
150
+ iframe_html = f"<iframe srcdoc='{clean_html_output}' style='width:100%; height:600px; border:none;'></iframe>"
151
+
152
+ # Debugging print to check the iframe HTML
153
+ # print("Iframe HTML:", iframe_html)
154
+
155
+ # Save the cleaned HTML content to a file (if you still want this feature)
156
  file_path = save_html_to_file(clean_html_output)
157
+
158
+ return iframe_html, gr.UploadButton(visible=False), gr.DownloadButton(label=f"Download Code", value=file_path, visible=True)
159
 
160
  def download_file():
161
  return [gr.UploadButton(label=f"Regenerate", visible=True), gr.DownloadButton(visible=False)]
162
 
163
+
164
  with gr.Blocks() as demo:
165
+ gr.Markdown("<center><h1> CV-2-Portfolio Site Generator</center></h1>")
166
+ gr.Markdown("<center><h2>Upload your CV in PDF or DOCX format for analysis and portfolio webpage generation.</center></h1>")
167
+
 
168
  u = gr.UploadButton("Upload CV (.pdf or .docx)", file_count="single")
169
  d = gr.DownloadButton("Download Portfolio", visible=False)
 
 
170
 
171
+ # HTML output preview section (which will be updated with iframe content after file processing)
172
+ output_preview = gr.HTML(value="<div style='width:100%; height:600px; border:1px solid #ccc; text-align:center;'>Upload a file to preview the generated portfolio</div>")
173
 
174
+ # Connect the upload button to the upload_file function and update the output preview
175
  u.upload(upload_file, u, [output_preview, u, d])
176
+
177
  # Handle download button click
178
  d.click(download_file, None, [u, d])
179
+
180
+ demo.launch(debug=True)
181
+
182
+
183
+