|
import gradio as gr |
|
|
|
|
|
def generate_outputs(user_prompt): |
|
report, recommendations, visualization = produce_outputs(combined_data) |
|
return report, recommendations, visualization |
|
|
|
from langchain.llms import OpenAI |
|
from langchain.agents import TextProcessingAgent |
|
from dspy.agents import Agent |
|
from dspy.utils import spawn_processes |
|
|
|
|
|
openai = OpenAI(api_key="KEY") |
|
|
|
|
|
|
|
|
|
|
|
|
|
def generate_synthetic_data(prompt): |
|
response = openai.complete(prompt=prompt, engine="text-davinci-003", max_tokens=100) |
|
return response.choices[0].text |
|
|
|
|
|
|
|
class DataProcessingAgent(Agent): |
|
def __init__(self): |
|
super().__init__() |
|
|
|
def process(self, data): |
|
|
|
processed_data = data.lower().strip() |
|
return processed_data |
|
|
|
|
|
|
|
team = [ |
|
OpenAI(api_key="YOUR_OPENAI_API_KEY", engine="text-davinci-003"), |
|
DataProcessingAgent(), |
|
] |
|
|
|
|
|
|
|
combined_data = f"{user_prompt}\n{generate_synthetic_data(f'Simulate scenarios for {user_prompt}')}" |
|
|
|
|
|
for agent in team: |
|
combined_data = agent.process(combined_data) |
|
|
|
|
|
|
|
def produce_outputs(processed_data): |
|
|
|
analysis = openai.complete(prompt=f"Analyze {processed_data}", engine="text-davinci-003", max_tokens=200) |
|
recommendations = openai.complete(prompt=f"Recommend strategies based on {processed_data}", engine="text-davinci-003", max_tokens=100) |
|
|
|
visualization = None |
|
return analysis.choices[0].text, recommendations.choices[0].text, visualization |
|
|
|
|
|
|
|
def generate_synthetic_data_distributed(prompt, num_nodes=3): |
|
|
|
processes = [spawn_processes(generate_synthetic_data, [f"Simulate scenarios for {prompt}"]) for _ in range(num_nodes)] |
|
|
|
|
|
synthetic_data_list = [] |
|
for process in processes: |
|
synthetic_data_list.extend(process.get()) |
|
|
|
|
|
return "\n".join(synthetic_data_list) |
|
|
|
|
|
|
|
synthetic_data = generate_synthetic_data_distributed(user_prompt) |
|
|
|
|
|
|
|
report, recommendations, visualization = produce_outputs(combined_data) |
|
|
|
|
|
|
|
print("Report:") |
|
print(report) |
|
print("\nRecommendations:") |
|
print(recommendations) |
|
print("\nVisualization:") |
|
print(visualization) |
|
|
|
|
|
gr.Interface(fn=generate_outputs, inputs=user_prompt, outputs=["text", "text", "image"]).launch() |
|
|