Spaces:
Running
Running
Commit
•
c0d9e36
1
Parent(s):
39e601c
Update app.py
Browse files
app.py
CHANGED
@@ -1,65 +1,24 @@
|
|
1 |
-
import
|
2 |
-
import
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
gguf_model.save(model_name)
|
26 |
-
# return the merged model for preview/demo
|
27 |
-
settings.IDEA_TO_APP_PREVIEW = gguf_model
|
28 |
-
|
29 |
-
from django.db import models
|
30 |
-
|
31 |
-
class CodeModel(models.Model):
|
32 |
-
name = models.CharField(max_length=100)
|
33 |
-
code = models.TextField()
|
34 |
-
|
35 |
-
class ImageModel(models.Model):
|
36 |
-
name = models.CharField(max_length=100)
|
37 |
-
image = models.ImageField(upload_to='images/')
|
38 |
-
|
39 |
-
def merge_models(model1, model2, function1, function3):
|
40 |
-
# merge the selected models and functions here
|
41 |
-
model1_objects = model1.objects.all()
|
42 |
-
model2_objects = model2.objects.all()
|
43 |
-
merged_objects = []
|
44 |
-
for obj1 in model1_objects:
|
45 |
-
obj2 = model2_objects.filter(name=obj1.name).first()
|
46 |
-
if obj2:
|
47 |
-
merged_obj = {
|
48 |
-
'name': obj1.name,
|
49 |
-
'code': function1(obj1.code),
|
50 |
-
'image': function3(obj2.image),
|
51 |
-
}
|
52 |
-
merged_objects.append(merged_obj)
|
53 |
-
return merged_objects
|
54 |
-
|
55 |
-
import openai
|
56 |
-
import jinja2
|
57 |
-
|
58 |
-
def function1(code):
|
59 |
-
# translate natural language to executable code here
|
60 |
-
# using the OpenAI API
|
61 |
-
openai.api_key = 'YOUR_OPENAI_API_KEY'
|
62 |
-
response = openai.Completion.create(
|
63 |
-
engine='code-davinci-002',
|
64 |
-
prompt=f'Translate this Python code to executable code: {code}'\
|
65 |
-
)
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
from huggingface_hub import HfApi
|
3 |
+
|
4 |
+
app = Flask(__name__)
|
5 |
+
api = HfApi()
|
6 |
+
|
7 |
+
@app.route('/search_datasets', methods=['GET'])
|
8 |
+
def search_datasets():
|
9 |
+
query = request.args.get('query')
|
10 |
+
datasets = api.list_datasets(search=query, full=True)
|
11 |
+
return jsonify(datasets)
|
12 |
+
|
13 |
+
@app.route('/run_inference', methods=['POST'])
|
14 |
+
def run_inference():
|
15 |
+
model_id = request.json['model_id']
|
16 |
+
inputs = request.json['inputs']
|
17 |
+
# Assuming the model is compatible with the pipeline API
|
18 |
+
from transformers import pipeline
|
19 |
+
model_pipeline = pipeline(task="text-generation", model=model_id)
|
20 |
+
results = model_pipeline(inputs)
|
21 |
+
return jsonify(results)
|
22 |
+
|
23 |
+
if __name__ == '__main__':
|
24 |
+
app.run(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|