AYVSH commited on
Commit
5819399
ยท
verified ยท
1 Parent(s): f8e7944

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -13
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
- # Call the OpenAI API to generate the summary
44
- response = client.chat.completions.create(
45
- model="gpt-4o", # Specify the model you want to use
46
- messages=[
47
- {"role": "system", "content": "You are a financial analyst summarizing stock filings."},
48
- {"role": "user", "content": prompt}
49
- ],
50
- temperature=0,
51
- max_tokens=150 # Limit the response length
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("Submit", variant="primary")
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...")