Mohit5899 commited on
Commit
14b20cf
·
verified ·
1 Parent(s): d9a824d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -6
app.py CHANGED
@@ -4,7 +4,7 @@ import os
4
  from groq import Groq
5
  from duckduckgo_search import DDGS
6
 
7
- # List of Groq models (defined globally to avoid NameError)
8
  groq_models = [
9
  "qwen-2.5-32b",
10
  "qwen-2.5-coder-32b",
@@ -27,14 +27,81 @@ groq_models = [
27
  "mixtral-8x7b-32768"
28
  ]
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  # Function to convert JSON to formatted text
31
  def json_to_text(filename):
32
  try:
33
- if not filename:
34
- return "Please select a JSON file."
35
  with open(filename, 'r') as json_file:
36
  data = json.load(json_file)
37
- return json.dumps(data, indent=2)
38
  except (FileNotFoundError, json.JSONDecodeError) as e:
39
  return f"Error: Could not load JSON file - {str(e)}"
40
 
@@ -67,7 +134,7 @@ def chat_with_json(api_key, model_name, filename, question):
67
  temperature=1,
68
  max_completion_tokens=1024,
69
  top_p=1,
70
- stream=False # Set to False for simplicity; can be True for streaming
71
  )
72
  answer = completion.choices[0].message.content
73
 
@@ -91,7 +158,7 @@ iface = gr.Interface(
91
  inputs=gr.Dropdown(choices=get_json_files(), label="Select JSON File"),
92
  outputs=gr.Markdown(),
93
  title="JSON to Text",
94
- description="Convert a JSON file to formatted text."
95
  )
96
 
97
  # Gradio Interface for Chat with JSON
 
4
  from groq import Groq
5
  from duckduckgo_search import DDGS
6
 
7
+ # List of Groq models
8
  groq_models = [
9
  "qwen-2.5-32b",
10
  "qwen-2.5-coder-32b",
 
27
  "mixtral-8x7b-32768"
28
  ]
29
 
30
+ # Function to format JSON into readable Markdown
31
+ def format_json_to_markdown(data):
32
+ markdown = "# Company Overview\n\n"
33
+
34
+ # Profile Section
35
+ profile = data.get("research", {}).get("profile", {})
36
+ markdown += "## Company Profile\n"
37
+ markdown += f"- **Company Name**: {profile.get('company_name', 'N/A')}\n"
38
+ markdown += f"- **Business Description**: {profile.get('business_description', 'N/A')}\n"
39
+ markdown += f"- **Headquarters**: {profile.get('headquarters', 'N/A')}\n"
40
+ markdown += f"- **Founded Year**: {profile.get('founded_year', 'N/A')}\n"
41
+ markdown += f"- **CEO**: {profile.get('ceo', 'N/A')}\n"
42
+ markdown += f"- **Employees**: {profile.get('employees', 'N/A')}\n"
43
+ markdown += f"- **Target Market**: {profile.get('target_market', 'N/A')}\n"
44
+ markdown += f"- **Products/Services**: \n"
45
+ for service in profile.get('products_services', []):
46
+ markdown += f" - {service}\n"
47
+ markdown += f"- **Business Model**: {profile.get('business_model', 'N/A')}\n"
48
+ markdown += f"- **Growth Strategy**: {profile.get('growth_strategy', 'N/A')}\n\n"
49
+
50
+ # Financials Section
51
+ financials = data.get("research", {}).get("financials", {})
52
+ markdown += "## Financial Highlights\n"
53
+ markdown += f"- **Revenue**: {financials.get('revenue', {}).get('₹ Crores', 'N/A') or financials.get('revenue', {}).get('total_revenue_2024', 'N/A')} ₹ Crores\n"
54
+ markdown += f"- **Revenue Growth**: {financials.get('revenue_growth', 'N/A')}% \n"
55
+ markdown += f"- **Net Income**: {financials.get('net_income', {}).get('₹ Crores', 'N/A') or financials.get('net_income', {}).get('2024', 'N/A')} ₹ Crores\n"
56
+ markdown += f"- **Profit Margin**: {financials.get('profit_margin', 'N/A')}% \n"
57
+ markdown += f"- **Debt to Equity**: {financials.get('debt_to_equity', 'N/A')}\n"
58
+
59
+ # Key Ratios Table
60
+ ratios = financials.get("key_ratios", {})
61
+ if ratios:
62
+ markdown += "\n### Key Financial Ratios\n"
63
+ markdown += "| Ratio | Value |\n"
64
+ markdown += "|-------------------|-------------|\n"
65
+ for key, value in ratios.items():
66
+ markdown += f"| {key.replace('_', ' ').title()} | {value} |\n"
67
+
68
+ # IPO Details Section
69
+ ipo = data.get("research", {}).get("ipo_details", {})
70
+ markdown += "\n## IPO Details\n"
71
+ markdown += f"- **IPO Date**: {ipo.get('ipo_date', 'N/A')}\n"
72
+ markdown += f"- **Price Range**: {ipo.get('price_range', 'N/A')}\n"
73
+ markdown += f"- **Final Price**: {ipo.get('final_price', 'N/A')} ₹\n"
74
+ markdown += f"- **Shares Offered**: {ipo.get('shares_offered', 'N/A')}\n"
75
+ markdown += f"- **Total Raised**: {ipo.get('total_raised', 'N/A')} ₹ Crores\n"
76
+ markdown += f"- **Use of Proceeds**: {ipo.get('use_of_proceeds', 'N/A')}\n"
77
+ markdown += f"- **Lock-Up Period**: {ipo.get('lock_up_period', 'N/A')}\n\n"
78
+
79
+ # Recommendation Section
80
+ recommendation = data.get("recommendation", {})
81
+ markdown += "## Investment Recommendation\n"
82
+ markdown += f"- **Recommendation**: {recommendation.get('recommendation', 'N/A')}\n"
83
+ markdown += f"- **Confidence Level**: {recommendation.get('confidence_level', 'N/A')}/10\n"
84
+ markdown += f"- **Price Targets**: Low: {recommendation.get('price_targets', {}).get('low', 'N/A')} | Base: {recommendation.get('price_targets', {}).get('base', 'N/A')} | High: {recommendation.get('price_targets', {}).get('high', 'N/A')} ₹\n"
85
+ markdown += f"- **Investment Horizon**: {recommendation.get('investment_horizon', 'N/A')}\n"
86
+ markdown += f"- **Key Metrics to Watch**: \n"
87
+ for metric in recommendation.get('key_metrics_to_watch', []):
88
+ markdown += f" - {metric}\n"
89
+ markdown += f"- **Entry Strategy**: {recommendation.get('entry_strategy', 'N/A')}\n"
90
+ markdown += f"- **Exit Conditions**: \n"
91
+ for condition in recommendation.get('exit_conditions', []):
92
+ markdown += f" - {condition}\n"
93
+ markdown += f"- **Summary Rationale**: {recommendation.get('summary_rationale', 'N/A')}\n"
94
+
95
+ return markdown
96
+
97
  # Function to convert JSON to formatted text
98
  def json_to_text(filename):
99
  try:
100
+ if not filename or filename == "No JSON files found":
101
+ return "Please select a valid JSON file."
102
  with open(filename, 'r') as json_file:
103
  data = json.load(json_file)
104
+ return format_json_to_markdown(data)
105
  except (FileNotFoundError, json.JSONDecodeError) as e:
106
  return f"Error: Could not load JSON file - {str(e)}"
107
 
 
134
  temperature=1,
135
  max_completion_tokens=1024,
136
  top_p=1,
137
+ stream=False
138
  )
139
  answer = completion.choices[0].message.content
140
 
 
158
  inputs=gr.Dropdown(choices=get_json_files(), label="Select JSON File"),
159
  outputs=gr.Markdown(),
160
  title="JSON to Text",
161
+ description="Convert a JSON file to a formatted, readable overview."
162
  )
163
 
164
  # Gradio Interface for Chat with JSON