Spaces:
Build error
Build error
Upload app2.py
Browse files
app2.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from pymongo import MongoClient
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
# MongoDB'ye bağlanma
|
| 6 |
+
client = MongoClient('mongodb://localhost:27017/')
|
| 7 |
+
db = client['yeniDatabase']
|
| 8 |
+
collection = db['train']
|
| 9 |
+
|
| 10 |
+
# Model eğitme fonksiyonu (örnek)
|
| 11 |
+
def train_model(filtered_data):
|
| 12 |
+
# Burada model eğitme işlemleri yapılır
|
| 13 |
+
# Örneğin, sadece veri boyutunu döndüren sahte bir model eğitimi
|
| 14 |
+
model_response = {
|
| 15 |
+
'status': 'success',
|
| 16 |
+
'message': 'Model trained successfully!',
|
| 17 |
+
'accuracy': 0.95, # Örnek doğruluk değeri
|
| 18 |
+
'data_size': len(filtered_data)
|
| 19 |
+
}
|
| 20 |
+
return model_response
|
| 21 |
+
|
| 22 |
+
# Gradio uygulaması için fonksiyon
|
| 23 |
+
def train_model_gradio(title,keywords, subcategories, subheadings):
|
| 24 |
+
# MongoDB'den ilgili verileri çekme
|
| 25 |
+
query = {
|
| 26 |
+
'title': {'$in': title},
|
| 27 |
+
'category': {'$in': keywords.split(',')},
|
| 28 |
+
'subcategory': {'$in': subcategories.split(',')},
|
| 29 |
+
'subheadings': {'$in': subheadings.split(',')}
|
| 30 |
+
}
|
| 31 |
+
filtered_data = list(collection.find(query))
|
| 32 |
+
|
| 33 |
+
# Model eğitme
|
| 34 |
+
response = train_model(filtered_data)
|
| 35 |
+
return response
|
| 36 |
+
|
| 37 |
+
# Gradio arayüzü
|
| 38 |
+
iface = gr.Interface(
|
| 39 |
+
fn=train_model_gradio,
|
| 40 |
+
inputs=[
|
| 41 |
+
gr.Textbox(label="Title"),
|
| 42 |
+
gr.Textbox(label="Keywords (comma-separated)"),
|
| 43 |
+
gr.Textbox(label="Subcategories (comma-separated)"),
|
| 44 |
+
gr.Textbox(label="Subheadings (comma-separated)")
|
| 45 |
+
],
|
| 46 |
+
outputs="json",
|
| 47 |
+
title="Model Training Interface",
|
| 48 |
+
description="Enter the titles, categories, subcategories, and subheadings to filter the data and train the model."
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
if __name__ == "__main__":
|
| 52 |
+
iface.launch()
|