Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain.embeddings.openai import OpenAIEmbeddings
|
| 2 |
+
from langchain.agents import create_csv_agent
|
| 3 |
+
from langchain.llms import OpenAI
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
import pandas as pd
|
| 7 |
+
file_name = 'gpt-generated-food-data.csv'
|
| 8 |
+
df = pd.read_csv(file_name)
|
| 9 |
+
|
| 10 |
+
agent = create_csv_agent(OpenAI(temperature=0),
|
| 11 |
+
file_name,
|
| 12 |
+
verbose=True)
|
| 13 |
+
|
| 14 |
+
agent.agent.llm_chain.prompt.template
|
| 15 |
+
|
| 16 |
+
def make_inference(query):
|
| 17 |
+
docs = docsearch.get_relevant_documents(query)
|
| 18 |
+
return(agent.run(input_documents=docs, question=query))
|
| 19 |
+
|
| 20 |
+
if __name__ == "__main__":
|
| 21 |
+
# make a gradio interface
|
| 22 |
+
import gradio as gr
|
| 23 |
+
|
| 24 |
+
gr.Interface(
|
| 25 |
+
make_inference,
|
| 26 |
+
[
|
| 27 |
+
gr.inputs.Textbox(lines=2, label="Query"),
|
| 28 |
+
],
|
| 29 |
+
gr.outputs.Textbox(label="Response"),
|
| 30 |
+
title="🍲SmartMenuCSV📄",
|
| 31 |
+
description='🍲SmartMenuCSV📄 is a tool that allows you to ask questions about food menu items. \n You can ask: \n "How many food items are gluten, vegan?" \n "How many food items have more than 400g calories and what are their names?" \n "What are the names of the food items with pickles and mayo?" \n "Are there more vegan or gluten-free items?" \n What is the average calories per food?" \n "Which ingredient appears the most and how many times does it appear?" \n "What is the ratio of vegan to gluten?" \n And more ...',
|
| 32 |
+
).launch()
|