Spaces:
Runtime error
Runtime error
Ari
commited on
Commit
·
6967dd4
1
Parent(s):
9d4ed25
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import openai
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
# Load your CSV file
|
| 6 |
+
data = pd.read_csv("RR.csv")
|
| 7 |
+
|
| 8 |
+
# Set your OpenAI API key
|
| 9 |
+
openai.api_key = "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"
|
| 10 |
+
|
| 11 |
+
def query_gpt(prompt):
|
| 12 |
+
model_engine = "text-davinci-002" # Use any available GPT model here
|
| 13 |
+
max_tokens = 50
|
| 14 |
+
|
| 15 |
+
response = openai.Completion.create(
|
| 16 |
+
engine=model_engine,
|
| 17 |
+
prompt=prompt,
|
| 18 |
+
max_tokens=max_tokens,
|
| 19 |
+
n=1,
|
| 20 |
+
stop=None,
|
| 21 |
+
temperature=0.7,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
message = response.choices[0].text.strip()
|
| 25 |
+
return message
|
| 26 |
+
|
| 27 |
+
def get_insights(question):
|
| 28 |
+
prompt = f"Given the following dataset:\n\n{data.to_string(index=False)}\n\n{question}"
|
| 29 |
+
answer = query_gpt(prompt)
|
| 30 |
+
return answer
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
markdown_data = f"Mock Dataset For GDS Social MBR :\n```\n{data.head(10).to_string(index=False)}\n```\n"
|
| 34 |
+
|
| 35 |
+
iface = gr.Interface(
|
| 36 |
+
fn=get_insights,
|
| 37 |
+
inputs=[
|
| 38 |
+
gr.inputs.Textbox(lines=2, label="Enter your question"),
|
| 39 |
+
],
|
| 40 |
+
outputs="text",
|
| 41 |
+
title="GPT-powered Q&A",
|
| 42 |
+
description=markdown_data,
|
| 43 |
+
examples=[
|
| 44 |
+
("Are there any trends or seasonality in calls handled?",),
|
| 45 |
+
("Are there any patterns that suggest a need for additional staff during specific periods?",),
|
| 46 |
+
("Can you identify any months with a significantly higher or lower number of calls handled compared to the overall average?",),
|
| 47 |
+
("Are there any patterns that suggest a need for additional staff during specific periods?",),
|
| 48 |
+
],
|
| 49 |
+
allow_screenshot=False,
|
| 50 |
+
theme="compact",
|
| 51 |
+
layout="vertical",
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
iface.launch(inbrowser=True)
|