Spaces:
Runtime error
Runtime error
Ari
commited on
Commit
·
99b345f
1
Parent(s):
0a32ec4
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,49 +13,56 @@ openai.api_key = "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"
|
|
| 13 |
graph1 = px.line(data, x="Month", y="Sales Forecasted")
|
| 14 |
graph2 = px.line(data, x="Month", y="Marketing Budget")
|
| 15 |
graph3 = px.line(data, x="Month", y="Sales Actual")
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
iface = gr.Interface(
|
| 20 |
fn=get_insights,
|
| 21 |
inputs=[
|
| 22 |
gr.inputs.Textbox(lines=2, label="Enter your question"),
|
| 23 |
],
|
| 24 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
title="GPT-powered Q&A",
|
| 26 |
description=markdown_data,
|
| 27 |
examples=[
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
],
|
| 33 |
allow_screenshot=False,
|
| 34 |
theme="compact",
|
| 35 |
layout="vertical",
|
| 36 |
-
|
| 37 |
-
gr.outputs.Graphic(type="plotly"),
|
| 38 |
-
gr.outputs.Graphic(type="plotly"),
|
| 39 |
-
gr.outputs.Graphic(type="plotly"),
|
| 40 |
-
gr.outputs.Graphic(type="plotly"),
|
| 41 |
-
gr.outputs.Graphic(type="plotly"),
|
| 42 |
-
],
|
| 43 |
-
)
|
| 44 |
-
|
| 45 |
-
iface.configure_output(
|
| 46 |
-
0, label="Sales Forecasted", type="plotly", data=graph1
|
| 47 |
-
)
|
| 48 |
-
iface.configure_output(
|
| 49 |
-
1, label="Marketing Budget", type="plotly", data=graph2
|
| 50 |
-
)
|
| 51 |
-
iface.configure_output(
|
| 52 |
-
2, label="Sales Actual", type="plotly", data=graph3
|
| 53 |
-
)
|
| 54 |
-
iface.configure_output(
|
| 55 |
-
3, label="Support Chats", type="plotly", data=graph4a
|
| 56 |
-
)
|
| 57 |
-
iface.configure_output(
|
| 58 |
-
4, label="Support Calls", type="plotly", data=graph4b
|
| 59 |
)
|
| 60 |
|
| 61 |
iface.launch(inbrowser=True)
|
|
|
|
| 13 |
graph1 = px.line(data, x="Month", y="Sales Forecasted")
|
| 14 |
graph2 = px.line(data, x="Month", y="Marketing Budget")
|
| 15 |
graph3 = px.line(data, x="Month", y="Sales Actual")
|
| 16 |
+
graph4 = px.line(data, x="Month", y=["Support Chats", "Support Calls"])
|
| 17 |
+
|
| 18 |
+
def query_gpt(prompt):
|
| 19 |
+
model_engine = "text-davinci-002" # Use any available GPT model here
|
| 20 |
+
max_tokens = 50
|
| 21 |
+
|
| 22 |
+
response = openai.Completion.create(
|
| 23 |
+
engine=model_engine,
|
| 24 |
+
prompt=prompt,
|
| 25 |
+
max_tokens=max_tokens,
|
| 26 |
+
n=1,
|
| 27 |
+
stop=None,
|
| 28 |
+
temperature=0.7,
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
message = response.choices[0].text.strip()
|
| 32 |
+
return message
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def get_insights(question):
|
| 36 |
+
prompt = f"Please answer the question: {question}\n\nRemember, base your answer solely on the data provided in the dataset."
|
| 37 |
+
answer = query_gpt(prompt)
|
| 38 |
+
return answer
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
markdown_data = "Mock Dataset Sales & Marketing Budget"
|
| 42 |
|
| 43 |
iface = gr.Interface(
|
| 44 |
fn=get_insights,
|
| 45 |
inputs=[
|
| 46 |
gr.inputs.Textbox(lines=2, label="Enter your question"),
|
| 47 |
],
|
| 48 |
+
outputs=[
|
| 49 |
+
gr.outputs.Plot(plot=graph1),
|
| 50 |
+
gr.outputs.Plot(plot=graph2),
|
| 51 |
+
gr.outputs.Plot(plot=graph3),
|
| 52 |
+
gr.outputs.Plot(plot=graph4),
|
| 53 |
+
],
|
| 54 |
title="GPT-powered Q&A",
|
| 55 |
description=markdown_data,
|
| 56 |
examples=[
|
| 57 |
+
"Are there any trends in sales forecast or actual sales?",
|
| 58 |
+
"How does the marketing budget correlate with the sales actual?",
|
| 59 |
+
"Can you identify any months with a significantly higher or lower number of support chats or calls compared to the overall average?",
|
| 60 |
+
"Are there any patterns that suggest a need for additional staff during specific periods based on support chats and calls?",
|
| 61 |
],
|
| 62 |
allow_screenshot=False,
|
| 63 |
theme="compact",
|
| 64 |
layout="vertical",
|
| 65 |
+
article="",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
)
|
| 67 |
|
| 68 |
iface.launch(inbrowser=True)
|