davidberenstein1957 HF staff commited on
Commit
21cc5dc
1 Parent(s): 7610e9b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -2
app.py CHANGED
@@ -81,6 +81,47 @@ def process_records_gradio(records, example_records, fields, question):
81
  except Exception as e:
82
  return f"Error: {str(e)}"
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
  interface = gr.Interface(
86
  fn=process_records_gradio,
@@ -92,8 +133,8 @@ interface = gr.Interface(
92
  ],
93
  examples=examples,
94
  outputs=gr.Code(label="Suggestions", language="json", lines=10),
95
- title="Record Processing Interface",
96
- description="Enter JSON data for `rg.Record.to_dict()`, `List[rg.Record.to_dict()]`, `List[Field].serialize()`, or `List[rg.Question.serialize()]` At least one of fields or question must be provided.",
97
  )
98
 
99
  if __name__ == "__main__":
 
81
  except Exception as e:
82
  return f"Error: {str(e)}"
83
 
84
+ description = """
85
+ Enter JSON data for `rg.Record.to_dict()`, `List[rg.Record.to_dict()]`, `List[Field].serialize()`, or `List[rg.Question.serialize()]` At least one of fields or question must be provided.
86
+
87
+ ```python
88
+ import json
89
+ import os
90
+ from gradio_client import Client
91
+
92
+ import argilla as rg
93
+
94
+ # Initialize Argilla client
95
+ client = rg.Argilla(
96
+ api_key=os.environ["ARGILLA_API_KEY"], api_url=os.environ["ARGILLA_API_URL"]
97
+ )
98
+
99
+ # Load the dataset
100
+ dataset = client.datasets(name="my_dataset", workspace="my_workspace")
101
+
102
+ # Prepare example data
103
+ example_field = dataset.settings.fields["my_input_field"].serialize()
104
+ example_question = dataset.settings.questions["my_question_to_predict"].serialize()
105
+
106
+ payload = {
107
+ "records": [next(dataset.records()).to_dict()],
108
+ "fields": [example_field],
109
+ "question": example_question,
110
+ }
111
+
112
+ # Use gradio client to process the data
113
+ client = Client("davidberenstein1957/distilabel-argilla-labeller")
114
+
115
+ result = client.predict(
116
+ records=json.dumps(payload["records"]),
117
+ example_records=json.dumps(payload["example_records"]),
118
+ fields=json.dumps(payload["fields"]),
119
+ question=json.dumps(payload["question"]),
120
+ api_name="/predict"
121
+ )
122
+
123
+ ```
124
+ """
125
 
126
  interface = gr.Interface(
127
  fn=process_records_gradio,
 
133
  ],
134
  examples=examples,
135
  outputs=gr.Code(label="Suggestions", language="json", lines=10),
136
+ title="Distilabel - ArgillaLabeller - Record Processing Interface",
137
+ description=description,
138
  )
139
 
140
  if __name__ == "__main__":