Codingxx commited on
Commit
e84c40c
·
verified ·
1 Parent(s): 6672892

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -28
app.py CHANGED
@@ -1,30 +1,7 @@
1
- import gradio as gr
2
- from transformers import AutoModelForCausalLM, AutoTokenizer
3
- import torch
4
 
5
- # Load the pre-trained DistilGPT-2 model and tokenizer
6
- model_name = "distilgpt2" # This is a smaller version of GPT-2
7
- model = AutoModelForCausalLM.from_pretrained(model_name)
8
- tokenizer = AutoTokenizer.from_pretrained(model_name)
9
 
10
- # Function to generate text based on user input
11
- def generate_response(user_input):
12
- # Encode the input prompt
13
- inputs = tokenizer.encode(user_input, return_tensors="pt")
14
-
15
- # Generate a response from the model
16
- with torch.no_grad(): # Disable gradient calculation for inference
17
- outputs = model.generate(inputs, max_length=100, num_return_sequences=1, no_repeat_ngram_size=2, top_p=0.9, top_k=50)
18
-
19
- # Decode the generated response
20
- response = tokenizer.decode(outputs[0], skip_special_tokens=True)
21
-
22
- return response
23
-
24
- # Create Gradio interface for text input and output
25
- iface = gr.Interface(fn=generate_response, inputs="text", outputs="text",
26
- title="DistilGPT-2 Chatbot",
27
- description="A lightweight conversational chatbot using DistilGPT-2.")
28
-
29
- # Launch the Gradio app
30
- iface.launch()
 
1
+ from fastapi import FastAPI
 
 
2
 
3
+ app = FastAPI()
 
 
 
4
 
5
+ @app.get("/")
6
+ def greet_json():
7
+ return {"Hello": "World!"}