ahmedembedded commited on
Commit
90a91f4
Β·
verified Β·
1 Parent(s): c9652e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -19
app.py CHANGED
@@ -1,12 +1,9 @@
1
- # app.py
2
- from fastapi import FastAPI, HTTPException
3
- from pydantic import BaseModel
4
  from peft import AutoPeftModelForCausalLM
5
  from transformers import AutoTokenizer
6
  import torch
7
 
8
- app = FastAPI()
9
-
10
  model_name = "ahmedembedded/AskFAST"
11
  load_in_4bit = True
12
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
@@ -14,6 +11,7 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
14
  model = AutoPeftModelForCausalLM.from_pretrained(model_name, load_in_4bit=load_in_4bit).to(device)
15
  tokenizer = AutoTokenizer.from_pretrained(model_name)
16
 
 
17
  FAST_prompt_context = """You are an admission officer at Fast University Pakistan. Your role is to answer queries related to the admission process at Fast University. You are expected to provide detailed and accurate responses to questions regarding:
18
 
19
  - Application deadlines
@@ -44,9 +42,6 @@ Stay focused on admissions-related topics only.
44
 
45
  past_prompts = []
46
 
47
- class Query(BaseModel):
48
- question: str
49
-
50
  def get_answer(question: str) -> str:
51
  if len(past_prompts) >= 10:
52
  past_prompts.pop(0)
@@ -71,14 +66,8 @@ def get_answer(question: str) -> str:
71
 
72
  return response_text.split('Response:')[1].split('### Input:')[0]
73
 
74
- @app.post("/predict/")
75
- async def predict(query: Query):
76
- try:
77
- answer = get_answer(query.question)
78
- return {"answer": answer}
79
- except Exception as e:
80
- raise HTTPException(status_code=500, detail=str(e))
81
-
82
- if __name__ == "__main__":
83
- import uvicorn
84
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
1
+ import gradio as gr
 
 
2
  from peft import AutoPeftModelForCausalLM
3
  from transformers import AutoTokenizer
4
  import torch
5
 
6
+ # Load the model and tokenizer
 
7
  model_name = "ahmedembedded/AskFAST"
8
  load_in_4bit = True
9
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 
11
  model = AutoPeftModelForCausalLM.from_pretrained(model_name, load_in_4bit=load_in_4bit).to(device)
12
  tokenizer = AutoTokenizer.from_pretrained(model_name)
13
 
14
+ # Define the prompt context
15
  FAST_prompt_context = """You are an admission officer at Fast University Pakistan. Your role is to answer queries related to the admission process at Fast University. You are expected to provide detailed and accurate responses to questions regarding:
16
 
17
  - Application deadlines
 
42
 
43
  past_prompts = []
44
 
 
 
 
45
  def get_answer(question: str) -> str:
46
  if len(past_prompts) >= 10:
47
  past_prompts.pop(0)
 
66
 
67
  return response_text.split('Response:')[1].split('### Input:')[0]
68
 
69
+ def predict(question):
70
+ return get_answer(question)
71
+
72
+ iface = gr.Interface(fn=predict, inputs="text", outputs="text")
73
+ iface.launch()