Spaces:
Runtime error
Runtime error
ikram
commited on
Commit
·
94f83a0
1
Parent(s):
07141a9
update app
Browse files- __pycache__/app.cpython-39.pyc +0 -0
- app.py +14 -15
__pycache__/app.cpython-39.pyc
ADDED
Binary file (1.49 kB). View file
|
|
app.py
CHANGED
@@ -1,29 +1,28 @@
|
|
1 |
import pandas as pd
|
2 |
import matplotlib.pyplot as plt
|
3 |
import seaborn as sns
|
4 |
-
import
|
5 |
-
from fastapi import FastAPI, UploadFile, File
|
6 |
import io
|
|
|
7 |
|
8 |
# Initialize FastAPI app
|
9 |
app = FastAPI()
|
10 |
|
11 |
-
#
|
|
|
|
|
12 |
def generate_viz_code(prompt: str) -> str:
|
13 |
"""Generate Python code for visualization based on user prompt."""
|
14 |
-
response =
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
{"role": "user", "content": prompt}
|
19 |
-
]
|
20 |
-
)
|
21 |
-
return response["choices"][0]["message"]["content"]
|
22 |
-
|
23 |
-
# Function to handle file upload and visualization
|
24 |
-
@app.post("/visualize")
|
25 |
def visualize_data(file: UploadFile = File(...), prompt: str = ""):
|
26 |
try:
|
|
|
|
|
|
|
|
|
27 |
# Read the uploaded Excel file
|
28 |
contents = file.file.read()
|
29 |
df = pd.read_excel(io.BytesIO(contents))
|
@@ -47,4 +46,4 @@ def visualize_data(file: UploadFile = File(...), prompt: str = ""):
|
|
47 |
# Uncomment below to run standalone FastAPI app
|
48 |
# if __name__ == "__main__":
|
49 |
# import uvicorn
|
50 |
-
# uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
1 |
import pandas as pd
|
2 |
import matplotlib.pyplot as plt
|
3 |
import seaborn as sns
|
4 |
+
from fastapi import FastAPI, UploadFile, File, HTTPException
|
|
|
5 |
import io
|
6 |
+
from transformers import pipeline
|
7 |
|
8 |
# Initialize FastAPI app
|
9 |
app = FastAPI()
|
10 |
|
11 |
+
# Load Hugging Face model for text-to-code generation
|
12 |
+
generator = pipeline("text-generation", model="Salesforce/codegen-350M-mono")
|
13 |
+
|
14 |
def generate_viz_code(prompt: str) -> str:
|
15 |
"""Generate Python code for visualization based on user prompt."""
|
16 |
+
response = generator(prompt, max_length=200)
|
17 |
+
return response[0]["generated_text"]
|
18 |
+
|
19 |
+
@app.post("/visualizeHuggingFace")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
def visualize_data(file: UploadFile = File(...), prompt: str = ""):
|
21 |
try:
|
22 |
+
# Ensure the file is an Excel file
|
23 |
+
if not file.filename.endswith(('.xls', '.xlsx')):
|
24 |
+
raise HTTPException(status_code=400, detail="Only Excel files (.xls, .xlsx) are supported.")
|
25 |
+
|
26 |
# Read the uploaded Excel file
|
27 |
contents = file.file.read()
|
28 |
df = pd.read_excel(io.BytesIO(contents))
|
|
|
46 |
# Uncomment below to run standalone FastAPI app
|
47 |
# if __name__ == "__main__":
|
48 |
# import uvicorn
|
49 |
+
# uvicorn.run(app, host="0.0.0.0", port=8000)
|