eesfeg commited on
Commit
87d0d62
·
1 Parent(s): 52bd739
Files changed (1) hide show
  1. app.py +5 -46
app.py CHANGED
@@ -1,48 +1,7 @@
1
- import torch
2
- from transformers import AutoTokenizer, AutoModelForCausalLM
3
- import gradio as gr
4
 
5
- # Initialize model and tokenizer
6
- MODEL_ID = "abdelac/tinyllama"
7
 
8
- @cache_resource
9
- def load_model():
10
- tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
11
- model = AutoModelForCausalLM.from_pretrained(
12
- MODEL_ID,
13
- torch_dtype=torch.float16,
14
- device_map="auto"
15
- )
16
- return tokenizer, model
17
-
18
- tokenizer, model = load_model()
19
-
20
- def respond(message, history):
21
- # Format chat history
22
- prompt = ""
23
- for user_msg, assistant_msg in history:
24
- prompt += f"Human: {user_msg}\nAssistant: {assistant_msg}\n"
25
- prompt += f"Human: {message}\nAssistant:"
26
-
27
- # Tokenize
28
- inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
29
-
30
- # Generate
31
- outputs = model.generate(
32
- **inputs,
33
- max_new_tokens=256,
34
- temperature=0.7,
35
- do_sample=True,
36
- pad_token_id=tokenizer.eos_token_id
37
- )
38
-
39
- # Decode
40
- response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
41
- return response
42
-
43
- # Create chat interface
44
- gr.ChatInterface(
45
- respond,
46
- title="TinyLlama Chat",
47
- description="Chat with TinyLlama model",
48
- ).launch()
 
1
+ from fastapi import FastAPI
 
 
2
 
3
+ app = FastAPI()
 
4
 
5
+ @app.get("/")
6
+ def greet_json():
7
+ return {"Hello": "World!"}