Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ client = OpenAI(
|
|
| 9 |
api_key=os.environ.get("OPENAI_API_KEY")
|
| 10 |
)
|
| 11 |
|
|
|
|
| 12 |
prompt_template = """
|
| 13 |
For any TYPE of document/pdf/filling STRICTLY stick to the format mentioned below:
|
| 14 |
๐ [Stock Name]
|
|
@@ -40,16 +41,19 @@ def analyze_pdf(file):
|
|
| 40 |
docs = loader.load()
|
| 41 |
combined_text = " ".join([doc.page_content for doc in docs])
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
return response.choices[0].message.content.strip()
|
| 55 |
|
|
@@ -57,16 +61,16 @@ def analyze_pdf(file):
|
|
| 57 |
return f"โ ๏ธ Error: {str(e)}"
|
| 58 |
|
| 59 |
# Gradio interface
|
| 60 |
-
with gr.Blocks(title="Stocker") as app:
|
| 61 |
# Title
|
| 62 |
-
gr.Markdown("## ๐ Stocker")
|
| 63 |
|
| 64 |
# File Upload
|
| 65 |
with gr.Row():
|
| 66 |
pdf_input = gr.File(label="Upload PDF", file_types=[".pdf"])
|
| 67 |
|
| 68 |
# Analyze Button
|
| 69 |
-
analyze_btn = gr.Button("
|
| 70 |
|
| 71 |
# Output
|
| 72 |
output = gr.Textbox(label="Analysis Summary", lines=10, placeholder="Your summary will appear here...")
|
|
|
|
| 9 |
api_key=os.environ.get("OPENAI_API_KEY")
|
| 10 |
)
|
| 11 |
|
| 12 |
+
# Your original prompt template
|
| 13 |
prompt_template = """
|
| 14 |
For any TYPE of document/pdf/filling STRICTLY stick to the format mentioned below:
|
| 15 |
๐ [Stock Name]
|
|
|
|
| 41 |
docs = loader.load()
|
| 42 |
combined_text = " ".join([doc.page_content for doc in docs])
|
| 43 |
|
| 44 |
+
# Prepare the prompt
|
| 45 |
+
prompt = prompt_template.format(text=combined_text)
|
| 46 |
+
|
| 47 |
+
# Call OpenAI API
|
| 48 |
+
response = client.chat.completions.create(
|
| 49 |
+
model="gpt-4o",
|
| 50 |
+
messages=[
|
| 51 |
+
{"role": "system", "content": "You are a financial analyst summarizing stock filings."},
|
| 52 |
+
{"role": "user", "content": prompt}
|
| 53 |
+
],
|
| 54 |
+
temperature=0,
|
| 55 |
+
max_tokens=150 # Token limit set to 150
|
| 56 |
+
)
|
| 57 |
|
| 58 |
return response.choices[0].message.content.strip()
|
| 59 |
|
|
|
|
| 61 |
return f"โ ๏ธ Error: {str(e)}"
|
| 62 |
|
| 63 |
# Gradio interface
|
| 64 |
+
with gr.Blocks(title="Stocker - Financial Analysis") as app:
|
| 65 |
# Title
|
| 66 |
+
gr.Markdown("## ๐ Stocker: Financial Analysis")
|
| 67 |
|
| 68 |
# File Upload
|
| 69 |
with gr.Row():
|
| 70 |
pdf_input = gr.File(label="Upload PDF", file_types=[".pdf"])
|
| 71 |
|
| 72 |
# Analyze Button
|
| 73 |
+
analyze_btn = gr.Button("Analyze", variant="primary")
|
| 74 |
|
| 75 |
# Output
|
| 76 |
output = gr.Textbox(label="Analysis Summary", lines=10, placeholder="Your summary will appear here...")
|