znation HF Staff commited on
Commit
59d692a
Β·
verified Β·
1 Parent(s): d2a4240

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. .claude/settings.local.json +9 -0
  2. README.md +22 -18
  3. app.py +12 -9
.claude/settings.local.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "WebFetch(domain:www.gradio.app)"
5
+ ],
6
+ "deny": [],
7
+ "ask": []
8
+ }
9
+ }
README.md CHANGED
@@ -7,6 +7,9 @@ sdk: gradio
7
  sdk_version: 6.1.0
8
  app_file: app.py
9
  pinned: false
 
 
 
10
  ---
11
 
12
  # πŸ“Š Visualizator
@@ -52,25 +55,25 @@ The application will launch and be accessible at `http://localhost:7860`
52
  - `requirements.txt`
53
  - `README.md`
54
 
55
- 3. (Optional) Enable OAuth for automatic authentication:
56
- - Go to your Space settings
57
- - Enable OAuth under the "Security" section
58
- - Follow the guide: https://huggingface.co/docs/hub/en/spaces-oauth
59
 
60
  ## Usage
61
 
62
- 1. **Enter Data URL**: Provide a URL to your CSV or TSV data file
63
- - Example: `https://raw.githubusercontent.com/vega/vega-datasets/master/data/cars.json`
 
64
 
65
- 2. **Write Your Query**: Describe the visualization you want in natural language
 
 
 
66
  - Example: "Show me a scatter plot of horsepower vs miles per gallon"
67
  - Example: "Create a bar chart of average acceleration by origin"
68
  - Example: "Display a line chart showing the trend of displacement over time"
69
 
70
- 3. **Add Token (Optional)**: Enter your HuggingFace API token for authenticated access
71
- - Get your token at: https://huggingface.co/settings/tokens
72
- - Required if running without OAuth or for higher rate limits
73
-
74
  4. **Generate**: Click "Generate Visualization" and the app will:
75
  - Load your data from the URL
76
  - Analyze the data schema
@@ -98,7 +101,7 @@ The application will launch and be accessible at `http://localhost:7860`
98
  - **Data Processing**: Pandas for data manipulation
99
  - **LLM Integration**: Hugging Face Inference API (Llama-3.3-70B-Instruct)
100
  - **Visualization**: Vega-Lite specifications rendered via Gradio Plot
101
- - **Authentication**: Optional HuggingFace OAuth integration
102
 
103
  ## Example Queries
104
 
@@ -110,9 +113,10 @@ The application will launch and be accessible at `http://localhost:7860`
110
 
111
  ## Configuration
112
 
113
- ### Environment Variables
114
 
115
- - `HF_TOKEN`: Optional default Hugging Face API token
 
116
 
117
  ## Troubleshooting
118
 
@@ -123,11 +127,11 @@ The application will launch and be accessible at `http://localhost:7860`
123
  **Issue**: "Failed to generate valid specification after 5 attempts"
124
  - Try rephrasing your query to be more specific
125
  - Ensure your data has appropriate columns for the requested visualization
126
- - Verify your HuggingFace token is valid (if using one)
127
 
128
- **Issue**: Rate limiting
129
- - Provide a HuggingFace API token for higher rate limits
130
- - Consider deploying to a Space with OAuth enabled
131
 
132
  ## License
133
 
 
7
  sdk_version: 6.1.0
8
  app_file: app.py
9
  pinned: false
10
+ hf_oauth: true
11
+ hf_oauth_scopes:
12
+ - inference-api
13
  ---
14
 
15
  # πŸ“Š Visualizator
 
55
  - `requirements.txt`
56
  - `README.md`
57
 
58
+ 3. OAuth is automatically enabled via the README.md configuration
59
+ - Users will see a "Sign in with Hugging Face" button
60
+ - OAuth provides automatic authentication with the `inference-api` scope
61
+ - No manual token input required
62
 
63
  ## Usage
64
 
65
+ 1. **Sign In**: Click "Sign in with Hugging Face" to authenticate (when deployed to Spaces)
66
+ - This provides automatic access to the Inference API
67
+ - For local development, the app will use unauthenticated API access
68
 
69
+ 2. **Enter Data URL**: Provide a URL to your CSV or TSV data file
70
+ - Example: `https://raw.githubusercontent.com/vega/vega-datasets/master/data/cars.csv`
71
+
72
+ 3. **Write Your Query**: Describe the visualization you want in natural language
73
  - Example: "Show me a scatter plot of horsepower vs miles per gallon"
74
  - Example: "Create a bar chart of average acceleration by origin"
75
  - Example: "Display a line chart showing the trend of displacement over time"
76
 
 
 
 
 
77
  4. **Generate**: Click "Generate Visualization" and the app will:
78
  - Load your data from the URL
79
  - Analyze the data schema
 
101
  - **Data Processing**: Pandas for data manipulation
102
  - **LLM Integration**: Hugging Face Inference API (Llama-3.3-70B-Instruct)
103
  - **Visualization**: Vega-Lite specifications rendered via Gradio Plot
104
+ - **Authentication**: HuggingFace OAuth integration with `inference-api` scope
105
 
106
  ## Example Queries
107
 
 
113
 
114
  ## Configuration
115
 
116
+ ### OAuth Scopes
117
 
118
+ The Space is configured with the following OAuth scope in README.md:
119
+ - `inference-api`: Required for using the Hugging Face Inference API to generate visualizations
120
 
121
  ## Troubleshooting
122
 
 
127
  **Issue**: "Failed to generate valid specification after 5 attempts"
128
  - Try rephrasing your query to be more specific
129
  - Ensure your data has appropriate columns for the requested visualization
130
+ - Make sure you're signed in with your Hugging Face account
131
 
132
+ **Issue**: Rate limiting or authentication errors
133
+ - Sign in with your Hugging Face account for authenticated API access
134
+ - The OAuth integration provides automatic authentication with proper rate limits
135
 
136
  ## License
137
 
app.py CHANGED
@@ -196,14 +196,14 @@ def create_visualization(
196
  log_messages.append(f"\nβœ— {error_msg}")
197
  return None, error_msg, "\n".join(log_messages)
198
 
199
- def visualize(data_url: str, query: str, token: Optional[str] = None):
200
  """
201
  Main function to create visualization for Gradio interface.
202
 
203
  Args:
204
  data_url: URL to the data file
205
  query: User's visualization query
206
- token: Optional HuggingFace token from OAuth
207
 
208
  Returns:
209
  Tuple of (vega_lite_spec_dict, log_message, error_message)
@@ -214,6 +214,9 @@ def visualize(data_url: str, query: str, token: Optional[str] = None):
214
  if not query or not query.strip():
215
  return None, "", "Please provide a visualization query"
216
 
 
 
 
217
  spec, error, log = create_visualization(data_url.strip(), query.strip(), token)
218
 
219
  if error:
@@ -227,6 +230,9 @@ def create_app():
227
  gr.Markdown("# πŸ“Š Visualizator")
228
  gr.Markdown("Generate data visualizations from URLs using natural language queries")
229
 
 
 
 
230
  with gr.Row():
231
  with gr.Column():
232
  data_url_input = gr.Textbox(
@@ -239,12 +245,6 @@ def create_app():
239
  placeholder="Show me the relationship between X and Y",
240
  lines=3
241
  )
242
- token_input = gr.Textbox(
243
- label="HuggingFace Token (optional)",
244
- placeholder="hf_...",
245
- type="password",
246
- lines=1
247
- )
248
  submit_btn = gr.Button("Generate Visualization", variant="primary")
249
 
250
  with gr.Column():
@@ -263,11 +263,14 @@ def create_app():
263
  ### Supported Formats
264
  - CSV files (.csv)
265
  - TSV files (.tsv)
 
 
 
266
  """)
267
 
268
  submit_btn.click(
269
  fn=visualize,
270
- inputs=[data_url_input, query_input, token_input],
271
  outputs=[output_plot, log_output, error_output]
272
  )
273
 
 
196
  log_messages.append(f"\nβœ— {error_msg}")
197
  return None, error_msg, "\n".join(log_messages)
198
 
199
+ def visualize(data_url: str, query: str, oauth_token: gr.OAuthToken | None):
200
  """
201
  Main function to create visualization for Gradio interface.
202
 
203
  Args:
204
  data_url: URL to the data file
205
  query: User's visualization query
206
+ oauth_token: OAuth token from Gradio (None if not logged in)
207
 
208
  Returns:
209
  Tuple of (vega_lite_spec_dict, log_message, error_message)
 
214
  if not query or not query.strip():
215
  return None, "", "Please provide a visualization query"
216
 
217
+ # Extract token from OAuth if user is logged in
218
+ token = oauth_token.token if oauth_token is not None else None
219
+
220
  spec, error, log = create_visualization(data_url.strip(), query.strip(), token)
221
 
222
  if error:
 
230
  gr.Markdown("# πŸ“Š Visualizator")
231
  gr.Markdown("Generate data visualizations from URLs using natural language queries")
232
 
233
+ # Add login button
234
+ gr.LoginButton()
235
+
236
  with gr.Row():
237
  with gr.Column():
238
  data_url_input = gr.Textbox(
 
245
  placeholder="Show me the relationship between X and Y",
246
  lines=3
247
  )
 
 
 
 
 
 
248
  submit_btn = gr.Button("Generate Visualization", variant="primary")
249
 
250
  with gr.Column():
 
263
  ### Supported Formats
264
  - CSV files (.csv)
265
  - TSV files (.tsv)
266
+
267
+ ### Note
268
+ Sign in with your Hugging Face account to use the Inference API for generating visualizations.
269
  """)
270
 
271
  submit_btn.click(
272
  fn=visualize,
273
+ inputs=[data_url_input, query_input],
274
  outputs=[output_plot, log_output, error_output]
275
  )
276