Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,46 +1,18 @@
|
|
| 1 |
-
|
| 2 |
-
from huggingface_hub import HfApi
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
logger = logging.getLogger()
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
return jsonify({"error": "No query parameter provided"}), 400
|
| 19 |
-
|
| 20 |
-
logger.info(f"Searching datasets with query: {query}")
|
| 21 |
-
datasets = api.list_datasets(search=query, full=True)
|
| 22 |
-
return jsonify(datasets)
|
| 23 |
-
except Exception as e:
|
| 24 |
-
logger.error(f"Failed to search datasets: {str(e)}")
|
| 25 |
-
return jsonify({"error": str(e)}), 500
|
| 26 |
|
| 27 |
-
|
| 28 |
-
def run_inference():
|
| 29 |
-
try:
|
| 30 |
-
model_id = request.json.get('model_id')
|
| 31 |
-
inputs = request.json.get('inputs')
|
| 32 |
-
|
| 33 |
-
if not model_id or not inputs:
|
| 34 |
-
logger.error("Model ID or inputs missing in the request.")
|
| 35 |
-
return jsonify({"error": "Model ID or inputs missing in the request"}), 400
|
| 36 |
-
|
| 37 |
-
logger.info(f"Running inference using model: {model_id}")
|
| 38 |
-
model_pipeline = pipeline(task="text-generation", model=model_id)
|
| 39 |
-
results = model_pipeline(inputs)
|
| 40 |
-
return jsonify(results)
|
| 41 |
-
except Exception as e:
|
| 42 |
-
logger.error(f"Failed to run inference: {str(e)}")
|
| 43 |
-
return jsonify({"error": str(e)}), 500
|
| 44 |
-
|
| 45 |
-
if __name__ == '__main__':
|
| 46 |
-
app.launch()
|
|
|
|
| 1 |
+
import gradio as gr
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Assuming you have access to OpenAI's API and Codex
|
| 5 |
+
# Replace 'your_api_key' with your actual OpenAI API key
|
| 6 |
+
code_completion = pipeline("text-generation", model="code-davinci-002", temperature=0.7, max_length=50, num_return_sequences=1, api_key='your_api_key')
|
| 7 |
|
| 8 |
+
def generate_code(input_code):
|
| 9 |
+
return code_completion(input_code, max_length=50, num_return_sequences=1)[0]['generated_text']
|
|
|
|
| 10 |
|
| 11 |
+
iface = gr.Interface(
|
| 12 |
+
fn=generate_code,
|
| 13 |
+
inputs=gr.inputs.Textbox(label="Enter your code snippet"),
|
| 14 |
+
outputs=gr.outputs.Textbox(label="Generated Code"),
|
| 15 |
+
title="Code Completion Assistant"
|
| 16 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|