DebabrataHalder commited on
Commit
d56e067
·
verified ·
1 Parent(s): 2292cfd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -71
app.py CHANGED
@@ -1,57 +1,10 @@
1
- # import os
2
- # import gradio as gr
3
- # from llama_cpp import Llama
4
- # from huggingface_hub import snapshot_download
5
-
6
- # # Optionally increase the HTTP timeout via an environment variable
7
- # os.environ["HF_HUB_HTTP_TIMEOUT"] = "3600" # 1 hour
8
-
9
- # # Download the model repository locally; this call blocks until the download completes.
10
- # local_repo = snapshot_download(
11
- # repo_id="DebabrataHalder/mysqlmodel",
12
- # revision="main",
13
- # local_dir_use_symlinks=False,
14
- # resume_download=True
15
- # )
16
-
17
- # # Load the model using the remote repo_id and specify the local cache directory
18
- # llm = Llama.from_pretrained(
19
- # repo_id="DebabrataHalder/mysqlmodel", # valid repo id format
20
- # filename="mysqlmodel.gguf",
21
- # cache_dir=local_repo, # point to the downloaded snapshot
22
- # n_ctx=2048, # adjust context size if needed
23
- # local_files_only=True # ensure only local files are used
24
- # )
25
-
26
- # def chat(prompt):
27
- # output = llm(prompt)
28
- # return output["choices"][0]["text"]
29
-
30
- # iface = gr.Interface(
31
- # fn=chat,
32
- # inputs="text",
33
- # outputs="text",
34
- # title="MySQL LLM Chat",
35
- # description="Chat interface for the MySQL finetuned model"
36
- # )
37
-
38
- # iface.launch()
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
  import os
48
- from fastapi import FastAPI
49
- from pydantic import BaseModel
50
  from llama_cpp import Llama
51
  from huggingface_hub import snapshot_download
52
 
53
- # Optionally increase the HTTP timeout via an environment variable (1 hour)
54
- os.environ["HF_HUB_HTTP_TIMEOUT"] = "3600"
55
 
56
  # Download the model repository locally; this call blocks until the download completes.
57
  local_repo = snapshot_download(
@@ -65,34 +18,27 @@ local_repo = snapshot_download(
65
  llm = Llama.from_pretrained(
66
  repo_id="DebabrataHalder/mysqlmodel", # valid repo id format
67
  filename="mysqlmodel.gguf",
68
- cache_dir=local_repo, # point to the downloaded snapshot
69
- n_ctx=2048, # adjust context size if needed
70
- local_files_only=True # ensure only local files are used
71
  )
72
 
73
- # Define a simple function to interact with the model
74
- def chat(prompt: str) -> str:
75
  output = llm(prompt)
76
  return output["choices"][0]["text"]
77
 
78
- # Set up FastAPI
79
- app = FastAPI(title="MySQL LLM Chat API")
 
 
 
 
 
 
 
 
80
 
81
- # Define request and response models using Pydantic
82
- class ChatRequest(BaseModel):
83
- prompt: str
84
 
85
- class ChatResponse(BaseModel):
86
- response: str
87
 
88
- @app.post("/chat", response_model=ChatResponse)
89
- async def chat_endpoint(chat_request: ChatRequest):
90
- prompt = chat_request.prompt
91
- response_text = chat(prompt)
92
- return ChatResponse(response=response_text)
93
 
94
- # If running locally, use: uvicorn app:app --reload
95
- if __name__ == "__main__":
96
- import uvicorn
97
- uvicorn.run(app, host="0.0.0.0", port=8000)
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
+ import gradio as gr
 
3
  from llama_cpp import Llama
4
  from huggingface_hub import snapshot_download
5
 
6
+ # Optionally increase the HTTP timeout via an environment variable
7
+ os.environ["HF_HUB_HTTP_TIMEOUT"] = "3600" # 1 hour
8
 
9
  # Download the model repository locally; this call blocks until the download completes.
10
  local_repo = snapshot_download(
 
18
  llm = Llama.from_pretrained(
19
  repo_id="DebabrataHalder/mysqlmodel", # valid repo id format
20
  filename="mysqlmodel.gguf",
21
+ cache_dir=local_repo, # point to the downloaded snapshot
22
+ n_ctx=2048, # adjust context size if needed
23
+ local_files_only=True # ensure only local files are used
24
  )
25
 
26
+ def chat(prompt):
 
27
  output = llm(prompt)
28
  return output["choices"][0]["text"]
29
 
30
+ iface = gr.Interface(
31
+ fn=chat,
32
+ inputs="text",
33
+ outputs="text",
34
+ title="MySQL LLM Chat",
35
+ description="Chat interface for the MySQL finetuned model"
36
+ )
37
+
38
+ iface.launch()
39
+
40
 
 
 
 
41
 
 
 
42
 
 
 
 
 
 
43
 
 
 
 
 
44