Spaces:
Configuration error

yonkasoft commited on
Commit
1373351
1 Parent(s): db8be92

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +15 -47
main.py CHANGED
@@ -1,55 +1,23 @@
1
- import gradio as gr
2
- from pymongo import MongoClient
3
- import pandas as pd
4
  import os
 
5
 
6
-
7
- secret_key = os.getenv('huggingface_key')
8
- print(f"Secret Key: {secret_key}")
9
-
10
-
11
 
12
  client = MongoClient('mongodb://localhost:27017/')
13
- db = client['EgitimDatabase']
14
- collection = db['test']
15
 
16
- def train_model(filtered_data):
17
-
18
-
19
- model_response = {
20
- 'status': 'success',
21
- 'message': 'Model trained successfully!',
22
- 'accuracy': 0.95, # Örnek doğruluk değeri
23
- 'data_size': len(filtered_data)
24
- }
25
- return model_response
26
 
27
- # Gradio uygulaması için fonksiyon
28
- def train_model_gradio(title,keywords,subheadings):
29
-
30
- query = {
31
- 'title': {'$in': title},
32
- 'category': {'$in': keywords.split(',')},
33
- 'subheadings': {'$in': subheadings.split(',')}
34
- }
35
- filtered_data = list(collection.find(query))
36
 
37
-
38
- response = train_model(filtered_data)
39
- return response
40
-
41
- # Gradio arayüzü
42
- iface = gr.Interface(
43
- fn=train_model_gradio,
44
- inputs=[
45
- gr.Textbox(label="Title"),
46
- gr.Textbox(label="Keywords (comma-separated)"),
47
- gr.Textbox(label="Subheadings (comma-separated)")
48
- ],
49
- outputs="json",
50
- title="Model Training Interface",
51
- description="Enter the titles, categories, subcategories, and subheadings to filter the data and train the model."
52
- )
53
 
54
- if __name__ == "__main__":
55
- iface.launch()
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
 
3
  import os
4
+ app = FastAPI()
5
 
6
+ model = load_model()
 
 
 
 
7
 
8
  client = MongoClient('mongodb://localhost:27017/')
9
+ db = client['']
10
+ collection = db['text']
11
 
 
 
 
 
 
 
 
 
 
 
12
 
 
 
 
 
 
 
 
 
 
13
 
14
+ class InputData(BaseModel):
15
+ title: str
16
+ keywords: str
17
+ subheadings: str
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
+ @app.post("/generate/")
20
+ async def generate(input_data: InputData):
21
+
22
+ result = model.predict(input_data)
23
+ return {"result": "generated_output"}