Spaces:
Sleeping
Sleeping
File size: 1,753 Bytes
4fb9f40 456461d 4fb9f40 456461d 4fb9f40 456461d 4fb9f40 456461d 4fb9f40 456461d 4fb9f40 456461d 4fb9f40 456461d 4fb9f40 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | import gradio as gr
from sentence_transformers import SentenceTransformer
from sklearn.cluster import KMeans
import pandas as pd
import plotly.express as px
import umap
model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
default_problems = """
I manually rename files every week
I convert PDFs to Excel
I copy data between spreadsheets
I send weekly reports manually
I merge CSV files daily
I manually download invoices
I extract tables from PDFs
I clean messy Excel sheets
I manually schedule social posts
I track expenses in spreadsheets
"""
def analyze_problems(text):
problems = [p.strip() for p in text.split("\n") if p.strip()]
embeddings = model.encode(problems)
k = min(5, len(problems))
kmeans = KMeans(n_clusters=k, random_state=0).fit(embeddings)
reducer = umap.UMAP()
coords = reducer.fit_transform(embeddings)
df = pd.DataFrame({
"problem": problems,
"cluster": kmeans.labels_,
"x": coords[:,0],
"y": coords[:,1]
})
fig = px.scatter(
df,
x="x",
y="y",
color=df["cluster"].astype(str),
text="problem",
title="Problem Market Map"
)
cluster_summary = df.groupby("cluster")["problem"].apply(list).to_dict()
summary = ""
for c, items in cluster_summary.items():
summary += f"\nCluster {c}\n"
for i in items:
summary += f"- {i}\n"
return summary, fig
demo = gr.Interface(
fn=analyze_problems,
inputs=gr.Textbox(value=default_problems, lines=15, label="Problem Signals"),
outputs=[
gr.Textbox(label="Problem Clusters"),
gr.Plot(label="Problem Market Map")
],
title="Problem Discovery Engine Demo",
)
demo.launch() |